@egain/ai-agent-sdk API Reference - v0.1.1 / StorageCacheAdapter
Class: StorageCacheAdapter
Browser storage cache adapter using localStorage or sessionStorage.
Automatically serializes values to JSON for storage. Falls back gracefully if storage is unavailable or full.
Example
typescript
// Use sessionStorage (cleared when tab closes)
const sessionCache = new StorageCacheAdapter('session');
// Use localStorage (persistent)
const localCache = new StorageCacheAdapter('local');
// Store data
sessionCache.set('config', {
value: { theme: 'dark' },
timestamp: Date.now()
});Implements
Table of contents
Constructors
Methods
Constructors
constructor
• new StorageCacheAdapter(storageType?): StorageCacheAdapter
Create a new StorageCacheAdapter
Parameters
| Name | Type | Default value | Description |
|---|---|---|---|
storageType | "local" | "session" | 'session' | Use 'local' for localStorage, 'session' for sessionStorage |
Returns
Throws
Error if not in a browser environment
Defined in
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