typerinth
Version:
A TypeScript library for interacting with the Modrinth API.
48 lines (47 loc) • 1.25 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const node_cache_1 = __importDefault(require("node-cache"));
class CacheManager {
cache;
cacheOptions;
constructor(cacheOptions) {
this.cacheOptions = cacheOptions;
this.cache = new node_cache_1.default({
stdTTL: cacheOptions.ttl,
checkperiod: cacheOptions.checkperiod,
});
}
/**
* Checks if the cache is enabled
* @returns {boolean} Whether the cache is enabled
*/
isEnabled() {
return this.cacheOptions.useCache ?? true;
}
/**
* Gets a value from the cache
* @param key - The key to get
*/
get(key) {
return this.cache.get(key);
}
/**
* Sets a value in the cache
* @param key - The key to set
* @param value - The value to set
*/
set(key, value) {
this.cache.set(key, value);
}
/**
* Deletes a value from the cache
* @param key - The key to delete
*/
delete(key) {
this.cache.del(key);
}
}
exports.default = CacheManager;