platform/packages/cache/example/cache_service.dart
2024-10-12 18:45:27 -07:00

24 lines
757 B
Dart

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