Skip to main content

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('eprint: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('eprint: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('eprint: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 eprint = await cache.get<StoredEprint>('eprint:xyz');
if (eprint) {
console.log('Cache hit:', eprint.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('eprint:xyz', eprint, 3600); // 1 hour TTL