new LRUCache(maxopt)
- Description:
Simple LRU cache in memory, supports get,put,del operations only, TTL can be specified in milliseconds as future time
- Source:
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
max |
number |
<optional> |
max number of items in the cache |
Example
const { lib } = require("backendjs")
const lru = new lib.LRUCache(1000)
Methods
(static) clean()
- Source:
(static) del(key) → {boolean}
- Description:
Remove a item from cache
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
key |
string |
Returns:
| Type | Description |
|---|---|
| boolean |
true if removed |
(static) get(key) → {any|undefined}
- Description:
Return an item by key
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
key |
string |
Returns:
| Type | Description |
|---|---|
| any | undefined |
an item if found |
(static) put(key, value, ttlopt)
- Description:
Put an item into cache, if total number of items exceed the max then the oldest item is removed
- Source:
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
key |
string | ||
value |
any | ||
ttl |
number |
<optional> |
in milliseconds |