Constructor
new Cache(app)
Constructor.
| Name | Type | Description |
|---|---|---|
app | object | Application container |
- Source
Methods
_purgeItem(name) → {void}
Remove a specific cache namespace or all first-level namespaces.
| Name | Type | Description |
|---|---|---|
name | string | Namespace name or |
- Source
- Type:
- void
(async) dispose() → {Promise.<void>}
Dispose internal reference.
- Source
- Type:
- Promise.<void>
getRootDir() → {string}
Get root directory for this class. It will be used to store all cache files, organized by namespace and TTL.
- Source
Absolute cache root directory
- Type:
- string
load(name, ttlDuropt) → {Promise.<any>}
Load cached content when available and not expired.
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
name | string | Cache key in namespaced path format | ||
ttlDur | number | | <optional> | 0 | TTL duration (milliseconds or parseable duration) |
- Source
Cached value, or undefined if missing/expired
- Type:
- Promise.<any>
prep(name, ttlDuropt) → {Object|undefined}
Prepare cache paths for a namespaced key and TTL.
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
name | string | Cache key in namespaced path format | ||
ttlDur | number | | <optional> | 0 | TTL duration (milliseconds or parseable duration) |
- Source
Prepared paths or undefined when not cacheable
- Type:
- Object |
undefined
purge(nameopt) → {void}
Purge cache by namespace or remove expired TTL directories.
| Name | Type | Attributes | Description |
|---|---|---|---|
name | string | <optional> | Optional namespace to remove directly |
- Source
- Type:
- void
save(name, item, ttlDuropt) → {Promise.<void>}
Save a value into cache for the given key and TTL directory.
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
name | string | Cache key in namespaced path format | ||
item | any | Value to persist | ||
ttlDur | number | | <optional> | 0 | TTL duration (milliseconds or parseable duration) |
- Source
Resolves when the value is written
- Type:
- Promise.<void>
sync(name, item, ttlDuropt) → {Promise.<any>}
Return cached content, and store the fallback value if cache is empty.
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
name | string | Cache key in namespaced path format | ||
item | any | Fallback value to save when cache miss happens | ||
ttlDur | number | | <optional> | 0 | TTL duration (milliseconds or parseable duration) |
- Source
Cached content
- Type:
- Promise.<any>