diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 00000000..c228706e --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,2 @@ +# 1.0.0 +* First version \ No newline at end of file diff --git a/README.md b/README.md index 4ce4017b..238be5e6 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,6 @@ Support for server-side caching in [Angel](https://angel-dart.github.io). ## `CacheService` -*TODO: Documentation* A `Service` class that caches data from one service, storing it in another. An imaginable use case is storing results from MongoDB or another database in @@ -17,6 +16,27 @@ A middleware that enables the caching of response serialization. This can improve the performance of sending objects that are complex to serialize. You can pass a [shouldCache] callback to determine which values should be cached. +```dart +main() async { + var app = new Angel()..lazyParseBodies = true; + + app.use( + '/api/todos', + new CacheService( + database: new AnonymousService( + index: ([params]) { + print('Fetched directly from the underlying service at ${new DateTime.now()}!'); + return ['foo', 'bar', 'baz']; + }, + read: (id, [params]) { + return {id: '$id at ${new DateTime.now()}'}; + } + ), + ), + ); +} +``` + ## `ResponseCache` A flexible response cache for Angel. diff --git a/lib/src/cache_service.dart b/lib/src/cache_service.dart index 78ca1fce..1729ae34 100644 --- a/lib/src/cache_service.dart +++ b/lib/src/cache_service.dart @@ -35,7 +35,6 @@ class CacheService extends Service { Future _getCached(Map params, _CachedItem get(), Future getFresh(), Future getCached(), Future save(data, DateTime now)) async { var cached = get(); - //print('$params => $cached'); var now = new DateTime.now().toUtc(); if (cached != null) { @@ -85,7 +84,7 @@ class CacheService extends Service { () => database.read(id, params), () => cache.read(id), (data, now) async { - _cache[id] = new _CachedItem(params, now); + _cache[id] = new _CachedItem(params, now, data); return await cache.modify(id, data); }, ); diff --git a/pubspec.yaml b/pubspec.yaml index 08842798..0f89dc07 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,10 @@ name: angel_cache +version: 1.0.0 +homepage: https://github.com/angel-dart/cache +description: Support for server-side caching in Angel. +author: Tobe O environment: - sdk: ">=1.19.0 <=2.0.0" + sdk: ">=1.19.0 <3.0.0" dependencies: angel_framework: ">=1.0.0-dev <2.0.0" intl: ^0.15.0