cache

Provides a secure interface for caching data within the Gingee application context. 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. IMPORTANT: Requires explicit permission to use the module. See docs/permissions-guide for more details.

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) 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>