mcache 1.0.2 mcache: ^1.0.2 copied to clipboard
Tools for caching values in memory. Supports setting the expiration of values.
Save values to cache:
void main(List<String> args) {
var cache = Cache(deleteOnExpire: false);
cache.set('name', 'Alex');
cache.set('key', '1o23fjadijs');
}
Save and retrieve values from cache:
void main(List<String> args) {
var cache = Cache(deleteOnExpire: false);
cache.set('name', 'Alex');
cache.set('key', '1o23fjadijs');
print(cache['name']);
print(cache['key']);
}
Save values and specify a lifetime for them:
void main(List<String> args) {
var cache = Cache(checkPeriod: const Duration(seconds: 1));
cache.set('name', 'Alex',
expirationSetting:
ExpirationSetting(expiration: const Duration(seconds: 3)));
cache.set('key', '1o23fjadijs',
expirationSetting:
ExpirationSetting(expiration: const Duration(seconds: 3)));
print(cache['name']);
print(cache['key']);
Future.delayed(const Duration(seconds: 4), () {
print(cache['name']);
print(cache['key']);
cache.dispose();
});
}
Записать значения и удалить их все:
void main(List<String> args) {
var cache = Cache(deleteOnExpire: false);
cache.set('name', 'Alex');
print(cache['name']);
cache.clear();
print(cache['name']);
}