This commit is contained in:
Tobe O 2018-05-15 23:54:34 -04:00
parent 2fdbfccd7d
commit 5295ea57eb
4 changed files with 29 additions and 4 deletions

2
CHANGELOG.md Normal file
View file

@ -0,0 +1,2 @@
# 1.0.0
* First version

View file

@ -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.

View file

@ -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);
},
);

View file

@ -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 <thosakwe@gmail.com>
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