Skip to content

@egain/ai-agent-sdk API Reference - v0.1.1 / MemoryCacheAdapter

Class: MemoryCacheAdapter

In-memory cache adapter for Node.js environments.

Uses a JavaScript Map for storage. Data persists only for the lifetime of the process. Suitable for server-side applications and testing.

Example

typescript
const cache = new MemoryCacheAdapter();

// Store a value
cache.set('user:123', { 
  value: { name: 'John' }, 
  timestamp: Date.now() 
});

// Retrieve the value
const entry = cache.get<{ name: string }>('user:123');
console.log(entry?.value.name); // "John"

Implements

Table of contents

Constructors

Methods

Constructors

constructor

new MemoryCacheAdapter(): MemoryCacheAdapter

Returns

MemoryCacheAdapter

Methods

get

get<T>(key): null | CacheEntry<T>

Get a value from the cache

Type parameters

Name
T

Parameters

NameTypeDescription
keystringThe cache key

Returns

null | CacheEntry<T>

The cached entry or null if not found

Implementation of

CacheAdapter.get

Defined in

core/api/CacheAdapter.ts:222


set

set<T>(key, entry): void

Set a value in the cache

Type parameters

Name
T

Parameters

NameTypeDescription
keystringThe cache key
entryCacheEntry<T>The cache entry with value and timestamp

Returns

void

Implementation of

CacheAdapter.set

Defined in

core/api/CacheAdapter.ts:230


delete

delete(key): void

Delete a value from the cache

Parameters

NameTypeDescription
keystringThe cache key

Returns

void

Implementation of

CacheAdapter.delete

Defined in

core/api/CacheAdapter.ts:234


clear

clear(prefix?): void

Clear all values from the cache

Parameters

NameTypeDescription
prefix?stringOptional prefix to only clear keys starting with this prefix

Returns

void

Implementation of

CacheAdapter.clear

Defined in

core/api/CacheAdapter.ts:238


keys

keys(prefix?): string[]

Get all keys in the cache

Parameters

NameTypeDescription
prefix?stringOptional prefix to filter keys

Returns

string[]

Array of matching cache keys

Implementation of

CacheAdapter.keys

Defined in

core/api/CacheAdapter.ts:250

Released under the MIT License.