Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mix1009/ffcache
ffcache(Flutter File Cache) is a file based key value store for caching.
https://github.com/mix1009/ffcache
cache dart file flutter
Last synced: 26 days ago
JSON representation
ffcache(Flutter File Cache) is a file based key value store for caching.
- Host: GitHub
- URL: https://github.com/mix1009/ffcache
- Owner: mix1009
- License: mit
- Created: 2019-05-23T13:05:07.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2021-10-26T08:29:31.000Z (about 3 years ago)
- Last Synced: 2024-09-28T09:27:57.831Z (about 1 month ago)
- Topics: cache, dart, file, flutter
- Language: Dart
- Homepage:
- Size: 188 KB
- Stars: 14
- Watchers: 3
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# ffcache
[![pub package](https://img.shields.io/pub/v/ffcache.svg)](https://pub.dartlang.org/packages/ffcache)
ffcache(Flutter File Cache) is a file based key value store. It stores cache in iOS/Android app's temporary folder. Cache automatically expires after expiration time. Web platform is also supported (uses idb_shim package).
## Usage
Most methods are asynchronous. So you should use await from an async function.
```
void testFFCache() async {final cache = FFCache();
// initialize. most methods call init() internally if not initialized.
// For web platform calling init() is required.
await cache.init();// insert 'key':'value' pair
await cache.setString('key', 'value');// get value for 'key'
final value = await cache.getString('key');// check if 'key' exists
if (await cache.has('key')) {// remove cache for 'key'
await cache.remove('key');
}// cache expires after Duration.
await cache.setStringWithTimeout('key', 'value', Duration(hours: 3));// remove all cache
await cache.clear();// setBytes & getBytes
{
final str = 'string data';
List bytes = utf8.encode(str);await cache.setBytes('bytes', bytes);
final rBytes = await cache.getBytes('bytes');
}// setJSON & getJSON
{
final jsonData = json.decode('''[{"id":1,"data":"string data","nested":{"id":"hello","flutter":"rocks"}}]''');
await cache.setJSON('json', jsonData);final rJsonData = await cache.getJSON('json');
}
}
```## API
Available from https://pub.dev/documentation/ffcache/latest/ffcache/FFCache-class.html
## How it works
Cache files are stored in the temporary directory of the app. It uses path_provider's getTemporaryDirectory(). Files in temporary directory can be deleted by the OS at any time. So, FFCache is not for general purpose key value store.Old cache entries are deleted when FFCache is initialized. By default, cache expires after 1 day.