@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
Methods
get
▸ get<T>(key): null | CacheEntry<T>
Get a value from the cache
Type parameters
| Name |
|---|
T |
Parameters
| Name | Type | Description |
|---|---|---|
key | string | The cache key |
Returns
null | CacheEntry<T>
The cached entry or null if not found
Implementation of
Defined in
set
▸ set<T>(key, entry): void
Set a value in the cache
Type parameters
| Name |
|---|
T |
Parameters
| Name | Type | Description |
|---|---|---|
key | string | The cache key |
entry | CacheEntry<T> | The cache entry with value and timestamp |
Returns
void
Implementation of
Defined in
delete
▸ delete(key): void
Delete a value from the cache
Parameters
| Name | Type | Description |
|---|---|---|
key | string | The cache key |
Returns
void
Implementation of
Defined in
clear
▸ clear(prefix?): void
Clear all values from the cache
Parameters
| Name | Type | Description |
|---|---|---|
prefix? | string | Optional prefix to only clear keys starting with this prefix |
Returns
void
Implementation of
Defined in
keys
▸ keys(prefix?): string[]
Get all keys in the cache
Parameters
| Name | Type | Description |
|---|---|---|
prefix? | string | Optional prefix to filter keys |
Returns
string[]
Array of matching cache keys