flutter_cache 0.1.0 copy "flutter_cache: ^0.1.0" to clipboard
flutter_cache: ^0.1.0 copied to clipboard

A simple cache package for flutter. This package is a wrapper for shared preference and makes working with shared preference easier.

example/example.dart

import 'package:flutter_cache/flutter_cache.dart' as cache;

void main() async {
  // create new cache.
  cache.remember('key', 'data');
  cache.write('key', 'data');

  // add Cache lifetime on create
  cache.remember('key', 'data', 120);
  cache.write('key', 'data', 120);

  // load Cache by key
  // return `defaultValue` if key not exists
  cache.load('key', 'defaultValue');

  // destroy single cache by key
  cache.destroy('key');

  // destroy all cache
  cache.clear();

  await cache.remember('key', () {
    return 'test'; // or logic fetching data from api;
  });

  // or

  await cache.remember('key', () => 'test');

  cache.remember('key', 'data', 120); // saved for 2 mins or 120 seconds
  cache.write('key', 'data', 120);

  // multi depth map datatype.
  cache.remember('key', {
    'name': 'Ashraf Kamarudin',
    'depth2': {
      'name': 'depth2',
      'depth3': {'name': 'depth3'}
    }
  });

  cache.load('key'); // will return data in map datatype.
}
22
likes
130
pub points
83%
popularity

Publisher

unverified uploader

A simple cache package for flutter. This package is a wrapper for shared preference and makes working with shared preference easier.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter, shared_preferences

More

Packages that depend on flutter_cache