Provides a secure interface for caching data within the Gingee application context.
Also exposes
module:cache.invalidateSysCache to drop engine static/transpile/instance
caches for path prefixes under the calling app (after runtime file replaces).
IMPORTANT: Requires explicit permission to use the module. See docs/permissions-guide for more details.- Description:
- Provides a secure interface for caching data within the Gingee application context.
Also exposes
module:cache.invalidateSysCacheto drop engine static/transpile/instance caches for path prefixes under the calling app (after runtime file replaces). IMPORTANT: Requires explicit permission to use the module. See docs/permissions-guide for more details.
- Provides a secure interface for caching data within the Gingee application context.
Also exposes
Members
(inner, constant) pendingWorkerInvalidate :Map.<string, {resolve: function(), reject: function(), timer: NodeJS.Timeout}>
Type:
- Map.<string, {resolve: function(), reject: function(), timer: NodeJS.Timeout}>
Methods
(static) clear() → {Promise.<void>}
- Description:
- Clears all cached values for the current application. This does not affect other applications' caches.
Example
const cache = require('cache');
await cache.clear();
console.log("All cache cleared.");
Throws:
-
If the clear operation fails.
- Type
- Error
Returns:
- Type
- Promise.<void>
(static) del(key) → {Promise.<void>}
- Description:
- Deletes a value from the application's cache using a namespaced key.
Example
const cache = require('cache');
await cache.del('my_key');
console.log("Value deleted from cache.");
Parameters:
| Name | Type | Description |
|---|---|---|
key |
string | The key to delete. |
Throws:
-
If the key is invalid or deletion fails.
- Type
- Error
Returns:
- Type
- Promise.<void>
(static) get(key) → {Promise.<any>}
- Description:
- Retrieves a value from the application's cache using a namespaced key.
Example
const cache = require('cache');
const value = await cache.get('my_key');
if (value) {
console.log(`Value found: ${JSON.stringify(value)}`);
} else {
console.log("Key not found in cache.");
}
Parameters:
| Name | Type | Description |
|---|---|---|
key |
string | The key to retrieve. |
Throws:
-
If the key is invalid or retrieval fails.
- Type
- Error
Returns:
A promise that resolves with the cached value, or null if not found.
- Type
- Promise.<any>
(static) invalidateSysCache(optionsopt) → {Promise.<{static: number, scripts: {transpile: number, instance: number}}>}
- Description:
- Drops engine caches for path prefixes under this app only — static file cache entries (`static:…`) and/or box transpile + sandboxed module instance caches. Does **not** run `platform.reloadApp` (no maintenance mode, no db/email reinit). Path rules match `fs` (leading `/` = app WEB/BOX root; else relative to the calling script). Empty options are a no-op. When called from an isolation worker, prefixes are resolved locally then forwarded to the master (static clear + fan-out to all workers).
Example
const cache = require('cache');
await cache.invalidateSysCache({
static: ['/assets/build'],
scripts: ['/lib', './generated'],
});
Parameters:
| Name | Type | Attributes | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
<optional> |
Properties
|
Returns:
- Type
- Promise.<{static: number, scripts: {transpile: number, instance: number}}>
(static) set(key, value, ttlopt) → {Promise.<void>}
- Description:
- Stores a value in the application's cache.
Example
const cache = require('cache');
await cache.set('my_key', { message: 'Hello, world!' }, 3600);
console.log("Value stored in cache.");
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
key |
string | The key to store the value under. | |
value |
any | The JSON-serializable value to store. | |
ttl |
number |
<optional> |
Optional Time-To-Live in seconds. Uses the server default if not provided. |
Throws:
-
If the key is invalid or storage fails.
- Type
- Error
Returns:
- Type
- Promise.<void>