CacheStrategy
CacheStrategy
The CacheStrategy defines how the underlying shared cache mechanism is implemented.
It is used by the CacheService to take care of storage and retrieval of items from the cache.
If you are using the DefaultCachePlugin
or the RedisCachePlugin
, you will not need to
manually specify a CacheStrategy, as these plugins will automatically configure the
appropriate strategy.
This is configured via the systemOptions.cacheStrategy
property of
your VendureConfig.
interface CacheStrategy extends InjectableStrategy {
get<T extends JsonCompatible<T>>(key: string): Promise<T | undefined>;
set<T extends JsonCompatible<T>>(key: string, value: T, options?: SetCacheKeyOptions): Promise<void>;
delete(key: string): Promise<void>;
invalidateTags(tags: string[]): Promise<void>;
}
- Extends:
InjectableStrategy
get
(key: string) => Promise<T | undefined>
Gets an item from the cache, or returns undefined if the key is not found, or the item has expired.
set
(key: string, value: T, options?: SetCacheKeyOptions) => Promise<void>
Sets a key-value pair in the cache. The value must be serializable, so cannot contain things like functions, circular data structures, class instances etc.
Optionally a "time to live" (ttl) can be specified, which means that the key will be considered stale after that many milliseconds.
delete
(key: string) => Promise<void>
Deletes an item from the cache.
invalidateTags
(tags: string[]) => Promise<void>
Deletes all items from the cache which contain at least one matching tag.
SetCacheKeyOptions
Options available when setting the value in the cache.
interface SetCacheKeyOptions {
ttl?: number;
tags?: string[];
}
ttl
number
The time-to-live for the cache key in milliseconds. This means that after this time period, the key will be considered stale and will no longer be returned from the cache. Omitting this is equivalent to having an infinite ttl.
tags
string[]
An array of tags which can be used to group cache keys together. This can be useful for bulk deletion of related keys.