Constructor
new CacheWorker(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, null otherwise
- Type
- Object
(async) purge(group, id) → {Boolean}
- Description:
Remove a record from cache.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
group |
String | group key |
id |
String | data key |
Returns:
true if removed
- Type
- Boolean
(async) purgeAll(group)
- Description:
Remove from cache all records for a given group.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
group |
String | group key |
(async) read(group, id) → {Object}
- Description:
Read a record from cache:
- from local copy if exists;
- send a read request to master otherwise.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
group |
String | group key |
id |
String | data key |
Returns:
data if any, null otherwise
- Type
- Object
(async) remove(group, id) → {Boolean}
- Description:
Remove a record from cache.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
group |
String | group key |
id |
String | data key |
Returns:
true if removed
- Type
- Boolean
(async) start()
- Description:
Start listening to IPC messages
- Source:
(async) stop()
- Description:
Stop worker
- Source:
(async) update(group, id, update) → {Object}
- Description:
Update data in the cache:
- send an update to the master;
- wait for a response with update status;
- update the data in the local copy and return updated object in case of success, throw error otherwise.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
group |
String | group key |
id |
String | data key |
update |
Object | data to store |
Returns:
data if succeeded, null otherwise, throws in case of an error
- Type
- Object
(async) write(group, id, data) → {Object}
- Description:
Write data to cache:
- send a write to the master;
- wait for a response with write status;
- write the data to local copy and return it in case of success, throw error otherwise.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
group |
String | group key |
id |
String | data key |
data |
Object | data to store |
Returns:
data if succeeded, null otherwise, throws in case of an error
- Type
- Object