mirror of
https://github.com/NekoMonci12/RakunNakun-AI.git
synced 2025-12-19 23:09:15 +00:00
32 lines
941 B
JavaScript
32 lines
941 B
JavaScript
// hybridCacheManager.js
|
|
|
|
const MongoCacheManager = require('./mongoCacheManager');
|
|
|
|
class HybridCacheManager {
|
|
/**
|
|
* @param {string} mongoUrl - Connection URL for MongoDB.
|
|
* @param {string} dbName - MongoDB database name.
|
|
* @param {string} collectionName - MongoDB collection name for cache.
|
|
*/
|
|
constructor(mongoUrl, dbName, collectionName = 'cache') {
|
|
this.mongoCache = new MongoCacheManager(mongoUrl, dbName, collectionName);
|
|
}
|
|
|
|
async getCachedResult(input) {
|
|
let result = await this.mongoCache.getCachedResult(input);
|
|
if (result) {
|
|
console.log("Hybrid Cache: Found result in MongoDB.");
|
|
return result;
|
|
}
|
|
console.log("Hybrid Cache: No cached result found.");
|
|
return null;
|
|
}
|
|
|
|
async setCache(input, value) {
|
|
await this.mongoCache.setCache(input, value);
|
|
console.log("Hybrid Cache: Stored value in both caches for key:", input);
|
|
}
|
|
}
|
|
|
|
module.exports = HybridCacheManager;
|