chrome_storage_cache 0.1.2
chrome_storage_cache: ^0.1.2 copied to clipboard
A Chrome Storage backed implementation of quiver's Cache.
chrome_storage_cache #
A quiver:Cache implementation backed by chrome.storage.local.
Usage #
Cache<K,V> myCache = new StorageCache('my-prefix');
myCache.set('favoriteColor','green');
myCache.get('favoriteColor').then((item) => print(item));
#=> 'green'
myCache.get('spoon', ifAbsent: (key) => 'There is no $key.');
#=> 'There is no spoon.'
myCache.get('spoon').then((item) => print(item));
#=> 'There is no spoon.'
Caveats #
- This is a work in progress. Proceed with caution.
- This has only been tested on Chrome Apps, not Chrome Extensions.
- You must supply a prefix to the StorageCache constructor.
- This only works for objects that can be serailzed via the Chrome Storage API. See below for more information.
Object serialization #
From the Chrome App JavaScript API docs:
Primitive values such as numbers will serialize as expected. Values with a
typeof "object"and"function"will typically serialize to{}, with the exception ofArray(serializes as expected),Date, andRegex(serialize using theirStringrepresentation).
The behavior under Dart is identical.