jaguar_cache_redis 0.1.1
jaguar_cache_redis: ^0.1.1 copied to clipboard
Cache implementation based on Redis
example/example.dart
// Copyright (c) 2017, teja. All rights reserved. Use of this source code
// is governed by a BSD-style license that can be found in the LICENSE file.
import 'dart:async';
import 'package:jaguar_cache_redis/jaguar_cache_redis.dart';
main() async {
final cache = new RedisCache(new Duration(minutes: 1));
// Upsert
await cache.upsert('one', 1, new Duration(seconds: 5));
print(await cache.read('one'));
// Replace
await cache.replace('one', 2, new Duration(seconds: 5));
print(await cache.read('one'));
// Expire
await new Future.delayed(new Duration(seconds: 5));
try {
await cache.read('one');
} catch (e) {
print('Success! $e');
}
await cache.upsert('one', 1.0, new Duration(seconds: 10));
await cache.upsert('two', 2.0, new Duration(seconds: 10));
print(await cache.readMany(['one', 'two']));
await cache.remove('one');
try {
await cache.read('one');
} catch (e) {
print('Success! $e');
}
}