platform/packages/cache/example/cache_service.dart
2021-05-30 08:46:13 +08:00

25 lines
734 B
Dart

import 'package:angel3_cache/angel3_cache.dart';
import 'package:angel3_framework/angel3_framework.dart';
import 'package:angel3_framework/http.dart';
main() async {
var app = Angel();
app.use(
'/api/todos',
CacheService(
cache: MapService(),
database: AnonymousService(index: ([params]) {
print(
'Fetched directly from the underlying service at ${new DateTime.now()}!');
return ['foo', 'bar', 'baz'];
}, read: (dynamic id, [params]) {
return {id: '$id at ${new DateTime.now()}'};
}),
),
);
var http = AngelHttp(app);
var server = await http.startServer('127.0.0.1', 3000);
print('Listening at http://${server.address.address}:${server.port}');
}