I am following the documentation of cachable. In particular the docs whow how to set different ttl for both primary and secondary. This is the snippet:
import { Cacheable } from 'cacheable';
import KeyvRedis from '@keyv/redis';
const secondary = new KeyvRedis('redis://user:pass@localhost:6379', { ttl: 1000 }); // <- NOT TRUE
const cache = new Cacheable({secondary, ttl: 100});
await cache.set('key', 'value'); // sets the value in the primary store with a ttl of 100 ms and secondary store with a ttl of 1000 ms
await sleep(500); // wait for .5 seconds
const value = await cache.get('key'); // gets the value from the secondary store and now sets the value in the primary store with a ttl of 500 ms which is what is left from the secondary store
The problem is that KeyvRedis does not seems to have a ttl in the KeyvRedisOptions type.
export type KeyvRedisOptions = {
/**
* Namespace for the current instance.
* Defaults to `keyv`
*/
namespace?: string;
/**
* Separator to use between namespace and key.
*/
keyPrefixSeparator?: string;
/**
* Number of keys to delete in a single batch.
*/
clearBatchSize?: number;
/**
* Enable Unlink instead of using Del for clearing keys. This is more performant but may not be supported by all Redis versions.
*/
useUnlink?: boolean;
/**
* Whether to allow clearing all keys when no namespace is set.
* If set to true and no namespace is set, iterate() will return all keys.
* Defaults to `false`.
*/
noNamespaceAffectsAll?: boolean;
/**
* This is used to throw an error if the client is not connected when trying to connect. By default, this is
* set to true so that it throws an error when trying to connect to the Redis server fails.
*/
throwOnConnectError?: boolean;
/**
* This is used to throw an error if at any point there is a failure. Use this if you want to
* ensure that all operations are successful and you want to handle errors. By default, this is
* set to false so that it does not throw an error on every operation and instead emits an error event
* and returns no-op responses.
* @default false
*/
throwOnErrors?: boolean;
/**
* Timeout in milliseconds for the connection. Default is undefined, which uses the default timeout of the Redis client.
* If set, it will throw an error if the connection does not succeed within the specified time.
* @default undefined
*/
connectionTimeout?: number;
};
Am i missing something?
I am following the documentation of cachable. In particular the docs whow how to set different ttl for both primary and secondary. This is the snippet:
The problem is that KeyvRedis does not seems to have a ttl in the
KeyvRedisOptionstype.Am i missing something?