CacheHandlerConfig
type CacheHandlerConfig = {
handlers: (Handler | undefined | null)[];
ttl?: Partial<TTLParameters>;
};
Properties
handlers
An array of cache handlers that conform to the Handler interface. Multiple caches can be used to implement various caching strategies or layers. See Handler
API reference for more information.
If a handler is undefined
or null
, it will be ignored. It may be useful when you don’t want to use a particular cache layer in a specific case. For example, you may want to opt out of using your remote cache during the build.
In the example below, we use a local cache and a Redis cache. If the Redis cache is not available, we will use only the local cache.
cache-handler.mjs
CacheHandler.onCreation(async () => {
let handler;
if (process.env.REDIS_AVAILABLE) {
await client.connect();
handler = await createRedisHandler({
client,
});
} else {
handler = {
// ...
};
}
return {
handlers: [handler],
};
});
ttl
Time-to-live (TTL) options for the cache entries. See TTLParameters
API reference for more information.