angel3_cache 8.1.1 copy "angel3_cache: ^8.1.1" to clipboard
angel3_cache: ^8.1.1 copied to clipboard

A service that provides HTTP caching to the response data for Angel3

example/main.dart

import 'package:angel3_cache/angel3_cache.dart';
import 'package:angel3_framework/angel3_framework.dart';
import 'package:angel3_framework/http.dart';

void main() async {
  var app = Angel();

  // Cache a glob
  var cache = ResponseCache()
    ..patterns.addAll([
      RegExp('^/?\\w+\\.txt'),
    ]);

  // Handle `if-modified-since` header, and also send cached content
  app.fallback(cache.handleRequest);

  // A simple handler that returns a different result every time.
  app.get(
      '/date.txt', (req, res) => res.write(DateTime.now().toIso8601String()));

  // Support purging the cache.
  app.addRoute('PURGE', '*', (req, res) {
    if (req.ip != '127.0.0.1') {
      throw AngelHttpException.forbidden();
    }

    cache.purge(req.uri!.path);
    print('Purged ${req.uri!.path}');
  });

  // The response finalizer that actually saves the content
  app.responseFinalizers.add(cache.responseFinalizer);

  var http = AngelHttp(app);
  var server = await http.startServer('127.0.0.1', 3000);
  print('Listening at http://${server.address.address}:${server.port}');
}
2
likes
140
pub points
0%
popularity

Publisher

verified publisherdukefirehawk.com

A service that provides HTTP caching to the response data for Angel3

Homepage
Repository (GitHub)
View/report issues
Contributing

Documentation

API reference

License

BSD-3-Clause (LICENSE)

Dependencies

angel3_framework, collection, logging, meta, pool

More

Packages that depend on angel3_cache