@noony-serverless/core
Version:
A Middy base framework compatible with Firebase and GCP Cloud Functions with TypeScript
131 lines • 3.67 kB
JavaScript
;
/**
* No-Operation Cache Adapter
*
* A cache adapter implementation that doesn't actually cache anything.
* Useful for testing scenarios, disabled caching configurations, or
* development environments where cache behavior needs to be bypassed.
*
* All operations return immediately without storing or retrieving data,
* ensuring that the guard system can operate without caching when needed.
*
* @author Noony Framework Team
* @version 1.0.0
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.NoopCacheAdapter = void 0;
/**
* No-operation cache adapter that doesn't cache anything
*
* This implementation provides the CacheAdapter interface but performs
* no actual caching operations. All get operations return null, all set
* operations are ignored, and all delete operations are no-ops.
*
* Useful for:
* - Testing scenarios where caching should be disabled
* - Development environments with live data
* - Troubleshooting cache-related issues
* - Performance baseline measurements
*/
class NoopCacheAdapter {
startTime = Date.now();
name;
// Track statistics even though we don't cache
stats = {
gets: 0,
sets: 0,
deletes: 0,
flushes: 0,
};
constructor(name = 'noop-cache') {
this.name = name;
}
/**
* Always returns null (no caching)
*
* @param key - Cache key to retrieve (ignored)
* @returns Promise resolving to null
*/
async get(_key) {
this.stats.gets++;
return null;
}
/**
* Does nothing (no caching)
*
* @param key - Cache key to store under (ignored)
* @param value - Value to cache (ignored)
* @param ttlMs - Time to live in milliseconds (ignored)
*/
async set(_key, _value, _ttlMs) {
this.stats.sets++;
// Intentionally do nothing
}
/**
* Does nothing (no caching)
*
* @param key - Cache key to delete (ignored)
*/
async delete(_key) {
this.stats.deletes++;
// Intentionally do nothing
}
/**
* Does nothing (no caching)
*
* @param pattern - Pattern to match keys (ignored)
*/
async deletePattern(_pattern) {
this.stats.deletes++;
// Intentionally do nothing
}
/**
* Does nothing (no caching)
*/
async flush() {
this.stats.flushes++;
// Intentionally do nothing
}
/**
* Get statistics for monitoring
*
* Returns statistics about operations performed, even though
* no actual caching occurs. This helps with monitoring and
* understanding system behavior.
*
* @returns Cache statistics with 0% hit rate
*/
async getStats() {
return {
totalEntries: 0, // Never stores anything
hits: 0, // Never hits (always returns null)
misses: this.stats.gets, // Every get is a miss
hitRate: 0, // Always 0% hit rate
memoryUsage: 0, // Uses no memory for caching
uptime: Date.now() - this.startTime,
};
}
/**
* Get adapter name for debugging
*/
getName() {
return this.name;
}
/**
* Get operation statistics for debugging
*/
getOperationStats() {
return { ...this.stats };
}
/**
* Check if this is a no-op cache adapter
*
* Utility method for other components to detect when
* caching is disabled and adjust behavior accordingly.
*/
isNoop() {
return true;
}
}
exports.NoopCacheAdapter = NoopCacheAdapter;
//# sourceMappingURL=NoopCacheAdapter.js.map