platform/packages/cache/example/cache_service.dart

25 lines
697 B
Dart
Raw Normal View History

2018-04-02 03:41:43 +00:00
import 'package:angel_cache/angel_cache.dart';
import 'package:angel_framework/angel_framework.dart';
main() async {
2018-10-21 09:35:04 +00:00
var app = new Angel();
2018-04-02 03:41:43 +00:00
app.use(
'/api/todos',
new CacheService(
2018-10-21 09:35:04 +00:00
cache: new MapService(),
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()}'};
}),
2018-04-02 03:41:43 +00:00
),
);
var http = new AngelHttp(app);
var server = await http.startServer('127.0.0.1', 3000);
print('Listening at http://${server.address.address}:${server.port}');
}