angel_cache 2.0.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 45

cache #

Pub build status

Support for server-side caching in Angel.

CacheService #

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 MemcacheD/Redis.

cacheSerializationResults #

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.

main() async {
    var app = new Angel()..lazyParseBodies = true;
      new CacheService(
        database: new AnonymousService(
          index: ([params]) {
            print('Fetched directly from the underlying service at ${new}!');
            return ['foo', 'bar', 'baz'];
          read: (id, [params]) {
            return {id: '$id at ${new}'};

ResponseCache #

A flexible response cache for Angel.

Use this to improve real and perceived response of Web applications, as well as to memoize expensive responses.

Supports the If-Modified-Since header, as well as storing the contents of response buffers in memory.

To initialize a simple cache:

Future configureServer(Angel app) async {
  // Simple instance.
  var cache = new ResponseCache();
  // You can also pass an invalidation timeout.
  var cache = new ResponseCache(timeout: const Duration(days: 2));
  // Close the cache when the application closes.
  app.shutdownHooks.add((_) => cache.close());
  // Use `patterns` to specify which resources should be cached.
    new RegExp(r'\.(png|jpg|gif|txt)$'),
    new Glob('public/**/*'),
  // REQUIRED: The middleware that serves cached responses
  // REQUIRED: The response finalizer that saves responses to the cache

Purging the Cache #

Call invalidate to remove a resource from a ResponseCache.

Some servers expect a reverse proxy or caching layer to support PURGE requests. If this is your case, make sure to include some sort of validation (maybe IP-based) to ensure no arbitrary attacker can hack your cache:

Future configureServer(Angel app) async {
  app.addRoute('PURGE', '*', (req, res) {
    if (req.ip != '')
      throw new AngelHttpException.forbidden();
    return cache.purge(req.uri.path);

2.0.1 #

  • Add ignoreQueryAndFragment to ResponseCache.
  • Rename CacheService.ignoreQuery to ignoreParams.

1.0.0 #

  • First version


import 'package:angel_cache/angel_cache.dart';
import 'package:angel_framework/angel_framework.dart';
import 'package:glob/glob.dart';

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

  // Cache a glob
  var cache = new ResponseCache()
      new Glob('/*.txt'),

  // Handle `if-modified-since` header, and also send cached content

  // A simple handler that returns a different result every time.
      (req, res) => res.write(new;

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

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

  // The response finalizer that actually saves the content

  var http = new AngelHttp(app);
  var server = await http.startServer('', 3000);
  print('Listening at http://${server.address.address}:${server.port}');

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  angel_cache: ^2.0.1

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:angel_cache/angel_cache.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Apr 1, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6

Health suggestions

Fix lib/src/cache.dart. (-4.41 points)

Analysis of lib/src/cache.dart reported 9 hints, including:

line 25 col 59: Use = to separate a named parameter from its default value.

line 54 col 19: Unnecessary new keyword.

line 83 col 21: Unnecessary new keyword.

line 97 col 15: Future results in async function bodies must be awaited or marked unawaited using package:pedantic.

line 118 col 19: Unnecessary new keyword.

Fix lib/src/cache_service.dart. (-1.99 points)

Analysis of lib/src/cache_service.dart reported 4 hints:

line 32 col 24: Use = to separate a named parameter from its default value.

line 44 col 15: Unnecessary new keyword.

line 79 col 20: Unnecessary new keyword.

line 93 col 22: Unnecessary new keyword.

Maintenance suggestions

Package is getting outdated. (-38.90 points)

The package was last published 72 weeks ago.

The package description is too short. (-19 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev <3.0.0
angel_framework ^2.0.0-alpha 2.1.1
collection ^1.0.0 1.14.12
meta ^1.0.0 1.1.8
pool ^1.0.0 1.4.0
Transitive dependencies
angel_container 1.1.0
angel_http_exception 1.1.0
angel_model 1.0.3
angel_route 3.1.0+1
async 2.4.1
charcode 1.1.3
code_buffer 1.0.1
combinator 1.1.0
convert 2.1.1
crypto 2.1.4
dart2_constant 1.0.2+dart2
file 5.1.0
http2 1.0.0
http_parser 3.1.4
http_server 0.9.8+3
intl 0.16.1
logging 0.11.4
matcher 0.12.6
merge_map 1.0.2
mime 0.9.6+3
mock_request 1.0.6
path 1.6.4
quiver 2.1.3
quiver_hashcode 2.0.0
recase 2.0.1 3.0.0
source_span 1.7.0
stack_trace 1.9.3
string_scanner 1.0.5
term_glyph 1.1.0
tuple 1.0.3
typed_data 1.1.6
uuid 2.0.4
Dev dependencies
angel_test ^2.0.0-alpha
glob ^1.0.0
http any
test ^1.0.0