Interface: ICacheProvider
Defined in: src/types/interfaces/cache.interface.ts:26
Cache provider interface for Redis.
Remarks
Provides caching for frequently accessed data.
Implementation notes:
- Uses Redis 7+
- All keys prefixed with "chive:"
- JSON serialization for complex values
- Automatic TTL management
Methods
delete()
delete(
key):Promise<void>
Defined in: src/types/interfaces/cache.interface.ts:77
Deletes a value from cache.
Parameters
key
string
Cache key
Returns
Promise<void>
Promise resolving when deleted
Example
await cache.delete('preprint:xyz');
exists()
exists(
key):Promise<boolean>
Defined in: src/types/interfaces/cache.interface.ts:94
Checks if a key exists in cache.
Parameters
key
string
Cache key
Returns
Promise<boolean>
True if key exists, false otherwise
Example
if (await cache.exists('preprint:xyz')) {
console.log('Key exists');
}
expire()
expire(
key,ttl):Promise<void>
Defined in: src/types/interfaces/cache.interface.ts:110
Sets expiration on existing key.
Parameters
key
string
Cache key
ttl
number
Time to live in seconds
Returns
Promise<void>
Promise resolving when TTL set
Example
await cache.expire('preprint:xyz', 1800); // 30 minutes
get()
get<
T>(key):Promise<null|T>
Defined in: src/types/interfaces/cache.interface.ts:44
Gets a value from cache.
Type Parameters
• T
Value type
Parameters
key
string
Cache key
Returns
Promise<null | T>
Cached value or null if not found/expired
Example
const preprint = await cache.get<StoredPreprint>('preprint:xyz');
if (preprint) {
console.log('Cache hit:', preprint.title);
}
set()
set<
T>(key,value,ttl?):Promise<void>
Defined in: src/types/interfaces/cache.interface.ts:62
Sets a value in cache.
Type Parameters
• T
Value type
Parameters
key
string
Cache key
value
T
Value to cache
ttl?
number
Time to live in seconds (optional, default: no expiration)
Returns
Promise<void>
Promise resolving when set
Example
await cache.set('preprint:xyz', preprint, 3600); // 1 hour TTL