"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Cache = void 0;
const lodash_1 = require("lodash");
const redis_1 = require("./redis");
const getRedis = (0, lodash_1.memoize)(() => (0, redis_1.createRedis)('CACHE'));
class Cache {
    static async get(key) {
        const { client, prefix } = getRedis();
        return client.get(`${prefix}:cache:${key}`);
    }
    static async set(key, value, ttl = 60) {
        const { client, prefix } = getRedis();
        await client.set(`${prefix}:cache:${key}`, value, 'EX', ttl);
    }
    static async getObj(key) {
        const { client, prefix } = getRedis();
        const value = await client.get(`${prefix}:cache:${key}`);
        return value ? JSON.parse(value) : null;
    }
    static async setObj(key, value, ttl = 60) {
        const { client, prefix } = getRedis();
        await client.set(`${prefix}:cache:${key}`, JSON.stringify(value), 'EX', ttl);
    }
}
exports.Cache = Cache;
Cache.__type = ['key', 'get', 'value', 'ttl', 'set', 'getObj', 'setObj', 'Cache', 'P&2!P&,J`0"sP&2!&2#"2$$`0%sP&2!P",J`0&sP&2!"2#"2$$`0\'s5w('];
//# sourceMappingURL=cache.js.map