void addCachePolicy(HTTPCachePolicy policy, bool shouldApplyToPath(String path))

Add a cache policy for file paths that return true for shouldApplyToPath.

When this instance serves a file, the headers determined by policy will be applied to files whose path returns true for shouldApplyToPath.

If a path would meet the criteria for multiple shouldApplyToPath functions added to this instance, the policy added earliest to this instance will be applied.

For example, the following adds a set of cache policies that will apply 'Cache-Control: no-cache, no-store' to '.widget' files, and 'Cache-Control: public' for any other files:

    fileController.addCachePolicy(const HTTPCachePolicy(preventCaching: true),
      (p) => p.endsWith(".widget"));
    fileController.addCachePolicy(const HTTPCachePolicy(),
      (p) => true);

Whereas the following incorrect example would apply 'Cache-Control: public' to '.widget' files because the first policy would always apply to it and the second policy would be ignored:

    fileController.addCachePolicy(const HTTPCachePolicy(),
      (p) => true);
    fileController.addCachePolicy(const HTTPCachePolicy(preventCaching: true),
      (p) => p.endsWith(".widget"));

Note that the 'Last-Modified' header is always applied to a response served from this instance.

Source

void addCachePolicy(HTTPCachePolicy policy, bool shouldApplyToPath(String path)) {
  _policyPairs.add(new _PolicyPair(policy, shouldApplyToPath));
}