Skip to content
pubscout

json_cache

4.0.0, released 2 years ago by dartoos.dev

Unifies local storage packages under a single object-oriented JSON caching interface.

$ flutter pub add json_cache
Source repository

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.

  • sqflite

    If you need a full SQL relational database instead of simple JSON key-value caching.

Works with

Packages commonly used together with json_cache: ones it builds on, ones built on it, and its own family.