A cache which stores its entries for some time.
Name | Default |
---|---|
T |
unknown |
+ new Cache<T>(options?
: ICahceOptions<T>): Cache<T>
Name | Default |
---|---|
T |
unknown |
Name | Type |
---|---|
options? |
ICahceOptions<T> |
Returns: Cache<T>
import Cache from 'timed-memory-cache';
const cache = new Cache<string>();
• get length(): number
Returns the number of entries in the cache
Returns: number
const cacheEntryCount = cache.length;
▸ clear(): void
Clears the cache
Returns: void
cache.clear();
▸ get(key
: string): T | undefined
Returns the value for a given key or undefined if nothing found
Name | Type |
---|---|
key |
string |
Returns: T | undefined
const value = cache.get('myKey');
▸ has(key
: string): boolean
Check if an entry with given key exists
Name | Type |
---|---|
key |
string |
Returns: boolean
const valueExists = cache.has('myKey');
▸ remove(key
: string): void
Removes an entry from the cache
Name | Type |
---|---|
key |
string |
Returns: void
cache.remove('myKey');
▸ set(key
: string, value
: T, options?
: ICacheEntryOptions<T>): void
Adds a new entry into the cache
Name | Type |
---|---|
key |
string |
value |
T |
options? |
ICacheEntryOptions<T> |
Returns: void
cache.set('myKey', 'myValue', { ttl: 120 * 1000 }, onRemove:(key,value) => { console.log("entry was removed after 120 seconds")});