@amirmarmul/waba-common
Version:

17 lines (16 loc) • 503 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.cache = void 0;
const Container_1 = require("../../core/infrastructure/Container");
async function cache(key, callback, ttl = 30) {
const cache = Container_1.Container.get('cacheService');
const value = await cache.get(key);
if (value) {
return value;
}
return callback().then(async (data) => {
await cache.set(key, data, ttl);
return data;
});
}
exports.cache = cache;