lazy_cache 2.0.1 copy "lazy_cache: ^2.0.1" to clipboard
lazy_cache: ^2.0.1 copied to clipboard

Provides an indexed local storage on top of the shared_preferences package.

Provides an indexed local storage on top of the shared_preferences package.

Features #

  • Build in index for all entries
  • Each entry is stored individually in local storage
  • clear() only removes entries under keyPrefix

Getting started #

flutter pub add lazy_cache

Usage #

import 'package:lazy_cache/lazy_cache.dart'

Example #

import 'package:lazy_cache/lazy_cache.dart' as lazy;

void main() async {
  var sampleCache = lazy.Cache(keyPrefix: 'sampleCache');

  for (int i = 0; i < 10; i++) {
    await sampleCache.set(i.toString(), 'Sample data: $i');
  }

  for (int i = 0; i < 10; i++) {
    print(await sampleCache.get(i.toString()));
  }

  print(sampleCache.index);

  sampleCache.clear();
}

Limitation #

  • Only support String data for simplicity.
  • toJson() and fromJson not provided as entries are not kept in memory.
  • On web, including browser extension, per entry maximum size is ~5M.

Additional information #

Part of flutter_lazy.

1
likes
50
pub points
0%
popularity

Publisher

verified publisherjsiu.dev

Provides an indexed local storage on top of the shared_preferences package.

Repository (GitHub)
View/report issues

License

MIT (LICENSE)

Dependencies

json_preferences, lazy_log

More

Packages that depend on lazy_cache