@vibe-flats/booking-engine-common-server 1.0.116 → 1.0.117
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -46,6 +46,6 @@ declare class CacheManager {
|
|
|
46
46
|
del(key: string): Promise<boolean>;
|
|
47
47
|
clear(): Promise<boolean>;
|
|
48
48
|
}
|
|
49
|
-
export declare const
|
|
50
|
-
export declare const
|
|
51
|
-
export default
|
|
49
|
+
export declare const vibeMongoCacheManager: CacheManager;
|
|
50
|
+
export declare const withVibeMongoCache: <T>(key: string, fetchFn: () => Promise<T>, ttl?: number) => Promise<T>;
|
|
51
|
+
export default vibeMongoCacheManager;
|
package/build/src/utils/cache.js
CHANGED
|
@@ -43,7 +43,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
43
43
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
44
44
|
};
|
|
45
45
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
46
|
-
exports.
|
|
46
|
+
exports.withVibeMongoCache = exports.vibeMongoCacheManager = void 0;
|
|
47
47
|
const keyv_1 = __importDefault(require("keyv"));
|
|
48
48
|
const mongo_1 = __importDefault(require("@keyv/mongo"));
|
|
49
49
|
class CacheManager {
|
|
@@ -150,23 +150,23 @@ class CacheManager {
|
|
|
150
150
|
}
|
|
151
151
|
}
|
|
152
152
|
// Create a singleton cache manager instance
|
|
153
|
-
exports.
|
|
153
|
+
exports.vibeMongoCacheManager = new CacheManager({
|
|
154
154
|
defaultTTL: 600000, // 10 minutes in milliseconds
|
|
155
155
|
keyPrefix: process.env.npm_package_name || 'no-process.env.npm_package_name'
|
|
156
156
|
});
|
|
157
157
|
// Helper function for caching with fallback (exactly like your example)
|
|
158
|
-
const
|
|
159
|
-
let result = yield exports.
|
|
158
|
+
const withVibeMongoCache = (key_1, fetchFn_1, ...args_1) => __awaiter(void 0, [key_1, fetchFn_1, ...args_1], void 0, function* (key, fetchFn, ttl = 600) {
|
|
159
|
+
let result = yield exports.vibeMongoCacheManager.get(key);
|
|
160
160
|
if (result) {
|
|
161
161
|
console.log(`Cache hit for key: ${key}`);
|
|
162
162
|
return result;
|
|
163
163
|
}
|
|
164
164
|
console.log(`Cache miss for key: ${key}`);
|
|
165
165
|
result = yield fetchFn();
|
|
166
|
-
yield exports.
|
|
166
|
+
yield exports.vibeMongoCacheManager.set(key, result, ttl);
|
|
167
167
|
console.log(`Cached data for key: ${key}`);
|
|
168
168
|
return result;
|
|
169
169
|
});
|
|
170
|
-
exports.
|
|
170
|
+
exports.withVibeMongoCache = withVibeMongoCache;
|
|
171
171
|
// Alternative export for convenience
|
|
172
|
-
exports.default = exports.
|
|
172
|
+
exports.default = exports.vibeMongoCacheManager;
|