cachecontrol 0.0.1 copy "cachecontrol: ^0.0.1" to clipboard
cachecontrol: ^0.0.1 copied to clipboard

Dart only (no dependencies) package to parse and format HTTP Cache-Control header.

cache-control #

Dart only (no dependencies) package to parse and format HTTP Cache-Control header.

Based on the TypeScript implementation and ported to Dart.

Getting started #

$ flutter pub add cachecontrol

API #

This library exposes a CacheControl record, parse() method and extension method format().

parse(header) #

import 'package:cachecontrol/cachecontrol.dart';

parse() takes a Cache-Control HTTP header value and returns a CacheControl instance.

For example, parse('max-age=31536000, public') will return [CacheControl] Dart record type:

CacheControl (
  maxAge: 31536000,
  sharedMaxAge: null,
  maxStale: false,
  maxStaleDuration: null,
  minFresh: null,
  immutable: false,
  mustRevalidate: false,
  noCache: false,
  noStore: false,
  noTransform: false,
  onlyIfCached: false,
  private: false,
  proxyRevalidate: false,
  public: true,
  staleIfError: null,
  staleWhileRevalidate: null
);

cacheControl.format() #

import 'package:cachecontrol/cachecontrol.dart';

format() is a method on CacheControl (or similar object) and returns a Cache-Control HTTP header value.

For example, parse('').copyWith(maxAge: 31536000, public: true).format() will return

max-age=31536000, public

Example usage #

res.setHeader(
  "Cache-Control",
  parse('')
    .copyWith(
      public: true,
      immutable: true,
    )
   .format()
);

Contributing #

Contributions are welcome. Please open up an issue or create PR if you would like to help out.

Make sure to run dart format and dart test before submitting a PR.

FAQ #

Why another cache-control library?

None of the existing libraries focus on just parsing the Cache-Control headers. There are some that expose Express (or connect-like) middlewares, and some unmaintained other ones that do rudimentary parsing of the header. The idea of this module is to parse the header according to the RFC with no further analysis or integration.

See also #

0
likes
120
pub points
65%
popularity

Publisher

verified publisherrodydavis.com

Dart only (no dependencies) package to parse and format HTTP Cache-Control header.

Repository (GitHub)
View/report issues

Documentation

API reference

License

Apache-2.0 (LICENSE)

More

Packages that depend on cachecontrol