json_cache
4.0.0, released 2 years ago by dartoos.dev
Unifies local storage packages under a single object-oriented JSON caching interface.
What it does
JsonCache is an object-oriented package that provides a uniform interface for caching user data locally in JSON format. It acts as a layer on top of various storage packages like SharedPreferences, Hive, LocalStorage, and FlutterSecureStorage.
AI-written summary of version 4.0.0, based on the package's README and metadata. Report an inaccuracy
Use it when
- You want to abstract your local storage layer behind a unified interface.
- You need to cache Map data easily or store simple values with boolean placeholders.
- You want to combine in-memory caching with persistent local storage seamlessly.
Skip it when
- You need a full relational database with complex querying capabilities.
- You require automatic code-generation for models and JSON serialization.
Strengths
- Provides a clean, uniform interface over multiple local storage backends.
- Includes thread-safe in-memory caching and diagnostic wrappers.
- Enables easy unit testing by depending on interfaces rather than concrete implementations.
Weaknesses
- Limited to JSON-encodable map structures and specific primitive wrappers.
- Relies on underlying third-party storage packages which must be independently configured.
Setup
- Kind
- Flutter widgets
- Effort
- Low
- Code generation
- No
- Direct dependencies
- 6
Requires initializing the chosen underlying storage package (e.g., SharedPreferences, Hive) before wrapping it with JsonCache.
final sharedPrefs = await SharedPreferences.getInstance();
final JsonCache jsonCache = JsonCacheMem(JsonCacheSharedPreferences(sharedPrefs));
await jsonCache.refresh('profile', {'name': 'John Doe'});
final profile = await jsonCache.value('profile');Alternatives
Packages that do the same job and could replace json_cache.
Works with
Packages commonly used together with json_cache: ones it builds on, ones built on it, and its own family.
- shared_preferencesjson_cache depends on itFlutter plugin for reading and writing simple key-value pairs. Wraps NSUserDefaults on iOS and SharedPreferences on Android.
- flutter_secure_storagejson_cache depends on itSecure key-value storage using platform-specific secure mechanisms
- hivejson_cache depends on itFast, pure Dart key-value store with optional AES-256 encryption
- safe_local_storagejson_cache depends on itKey-value storage library for Dart/Flutter that safely reads and writes local data.
- mutexjson_cache depends on itMutual exclusion locks and read-write locks for asynchronous Dart code
- localstoragejson_cache depends on itLocalStorage for Flutter and Web, alternative to React Native's AsyncStorage.