Skip to content

5. Response caching

Yauheni Abramovich edited this page Nov 25, 2023 · 1 revision

UNCORS provides caching of requests for optimizing the development process. The main idea is caching very expensive or frequently recurring queries via url globs.

For each mapping, a list of url globs that need to be cached can be specified

mappings:
  - from: ...
    to: ...
    cache:
      - /api/info
      - /api/users/**

Patterns

UNCORS supports the following special terms in the patterns:

Special Terms Meaning
* matches any sequence of non-path-separators
/**/ matches zero or more directories
? matches any single non-path-separator character
[class] matches any single non-path-separator character against a class of characters ([see "character classes"])
{alt1,...} matches a sequence of characters if one of the comma-separated alternatives matches

Any character with a special meaning can be escaped with a backslash (\).

A doublestar (**) should appear surrounded by path separators such as /**/. A mid-pattern doublestar (**) behaves like bash's globstar option: a pattern such as path/to/**.txt would return the same results as path/to/*.txt. The pattern you're looking for is path/to/**/*.txt.

Character Classes

Character classes support the following:

Class Meaning
[abc] matches any single character within the set
[a-z] matches any single character in the range
[^class] matches any single character which does not match the class
[!class] same as ^: negates the class

Global cache settings

Cache settings can be configured globally in the cache-config section of the configuration file:

cache-config:
  methods: [ GET ]
  expiration-time: 10m
  clear-time: 10m

Where methods is a list of HTTP methods to cache, by default only GET requests are cached. expiration-time is the time after which a cached response is considered stale and will be revalidated. clear-time is the time after which a cached response is removed from the cache.