A Cache Store is responsible for storing and retrieving cached responses.
It is also responsible for deciding which specific response to use based off of
a response's Vary
header (if present).
The MemoryCacheStore
stores the responses in-memory.
Options
maxEntries
- The maximum amount of responses to store. DefaultInfinity
.maxEntrySize
- The maximum size in bytes that a response's body can be. If a response's body is greater than or equal to this, the response will not be cached.
The store must implement the following functions:
This tells the cache interceptor if the store is full or not. If this is true, the cache interceptor will not attempt to cache the response.
Parameters:
- req
Dispatcher.RequestOptions
- Incoming request
Returns: CacheStoreReadable | Promise<CacheStoreReadable | undefined> | undefined
- If the request is cached, a readable for the body is returned. Otherwise, undefined
is returned.
Parameters:
- req
Dispatcher.RequestOptions
- Incoming request - value
CacheStoreValue
- Response to store
Returns: CacheStoreWriteable | undefined
- If the store is full, return undefined
. Otherwise, return a writable so that the cache interceptor can stream the body and trailers to the store.
This is an interface containing the majority of a response's data (minus the body).
number
- The response's HTTP status code.
string
- The response's HTTP status message.
(Buffer | Buffer[])[]
- The response's headers.
string[] | undefined
- The response's trailers.
Record<string, string> | undefined
- The headers defined by the response's Vary
header
and their respective values for later comparison
For example, for a response like
Vary: content-encoding, accepts
content-encoding: utf8
accepts: application/json
This would be
{
'content-encoding': 'utf8',
accepts: 'application/json'
}
number
- Time in millis that this value was cached.
number
- Time in millis that this value is considered stale.
number
- Time in millis that this value is to be deleted from the cache. This
is either the same sa staleAt or the max-stale
caching directive.
The store must not return a response after the time defined in this property.
This extends Node's Readable
and defines extra properties relevant to the cache interceptor.
The response's CacheStoreValue
This extends Node's Writable
and defines extra properties relevant to the cache interceptor.
If the response has trailers, the cache interceptor will pass them to the cache interceptor through this method.