Constructor
new CacheMaster(size)
- Description:
Constructor
- Source:
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
size |
Number |
100
|
max number of cache groups |
Methods
cls(group) → {Object}
- Description:
Just a handy method which returns an object with partials with given group.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
group |
String | group name |
Returns:
object with all the {@code CacheWorker} methods without group
- Type
- Object
has(group, id) → {Object}
- Description:
Check if local copy has data under the key.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
group |
String | group key |
id |
String | data key |
Returns:
data if any, undefined otherwise
- Type
- Object
init(group, age, size)
- Description:
Register a set of operators for a particular cache group.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
group |
String | group key |
options.init |
function | initializer - an "async () => [Object]" kind of function, preloads data to cache on startup |
options.Cls |
Array.<string> | class - an optional array of ["require path", "export name"] which resolves to a Jsonable subclass to construct instances |
options.read |
function | reader - an "async (key) => Object" kind of function, returns data to cache if any for the key supplied |
options.write |
function | writer - an "async (key, data) => Object" kind of function, persists the data cached if needed (must return the data persisted on success) |
options.update |
function | updater - an "async (key, update) => Object" kind of function, updates persisted data if needed |
options.remove |
function | remover - an "async (key) => Object" kind of function, removes persisted data if needed |
age |
int | how long in ms to keep records in memory for the group |
size |
int | how much records to keep in memory for the group |
(async) purge(group, id, from) → {Boolean}
- Description:
Remove a record from cache.
- Source:
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
group |
String | group key |
|
id |
String | data key |
|
from |
int |
0
|
originating pid if any |
Returns:
true if removed
- Type
- Boolean
(async) purgeAll(group, from) → {Boolean}
- Description:
Remove from cache all record for given group.
- Source:
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
group |
String | group key |
|
from |
int |
0
|
originating pid if any |
Returns:
true if removed
- Type
- Boolean
(async) read(group, id, from) → {Object}
- Description:
Read a record from cache:
- from local copy if exists;
- send a read request to master otherwise.
- Source:
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
group |
String | group key |
|
id |
String | data key |
|
from |
int |
0
|
originating pid if any |
Returns:
data if any, null otherwise
- Type
- Object
(async) remove(group, id, from) → {Boolean}
- Description:
Remove a record from cache.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
group |
String | group key |
id |
String | data key |
from |
int | originating pid if any |
Returns:
true if removed
- Type
- Boolean
(async) start() → {Promise.<undefined>}
- Description:
Attach to IPC
- Source:
Returns:
void
- Type
- Promise.<undefined>
stop()
- Description:
Detaches IPC instance
- Source:
(async) update(group, id, update, from) → {Object}
- Description:
Update data in the cache
- Source:
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
group |
String | group key |
|
id |
String | data key |
|
update |
Object | data to store |
|
from |
int |
0
|
originating pid if any |
Returns:
data if succeeded, null otherwise, throws in case of an error
- Type
- Object
(async) write(group, id, data, from) → {Object}
- Description:
Write data to the cache
- Source:
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
group |
String | group key |
|
id |
String | data key |
|
data |
Object | data to store |
|
from |
int |
0
|
originating pid if any |
Returns:
data if succeeded, null otherwise, throws in case of an error
- Type
- Object