Constructor
new DataStore(size, age, dispose, Cls)
- Description:
Constructor
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
size |
int | max number of items to store |
age |
int | max life of an object in ms |
dispose |
function | called whenever object is shifted from cache |
Cls |
Class | class for data objects |
Members
length
- Description:
Length getter
- Source:
Length getter
Methods
iterate(f)
- Description:
Iterate through all stored items
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
f |
function | function(id, item) to call with every item |
read(id) → {Any}
- Description:
Read value by key
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
id |
String | key |
Returns:
value or undefined if no value under such key is stored
- Type
- Any
remove(id)
- Description:
Remove an item from the store
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
id |
String | id of the item to remove |
update(id, set) → {Boolean}
- Description:
Update value stored under key with $set-like update
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
id |
String | key |
set |
Object | flattened object of {attr1: 2, 'obj.attr2': 3} kind |
Returns:
true if updated, false in case no object is stored under key
- Type
- Boolean
write(id, data) → {Object}
- Description:
Store value
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
id |
String | key |
data |
Object | value (pass null to delete data record) |
Returns:
returns the data supplied if it was stored, undefined otherwise
- Type
- Object