node-artifact-api
Version:
A node module wrapper for the Valve official Artifact API
56 lines (55 loc) • 1.53 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const constants_1 = require("../helpers/constants");
class ArtifactCache {
constructor() {
this.CARDS_CACHE = {};
this.SETS_CACHE = {};
}
getCacheCard(cardId, clearCache = false) {
if (clearCache) {
this.CARDS_CACHE = {};
return null;
}
try {
const fetchedCard = this.CARDS_CACHE[cardId];
if (fetchedCard) {
return fetchedCard;
}
return null;
}
catch (e) {
return null;
}
}
getCacheSet(setId, clearCache = false) {
if (clearCache) {
this.SETS_CACHE = {};
return null;
}
try {
const fetchedSet = this.SETS_CACHE[setId];
if (fetchedSet) {
const cacheTime = parseInt(fetchedSet.cacheInfo.expire_time, 10);
if (cacheTime > constants_1.CURRENT_UNIX_TIME()) {
return fetchedSet.set;
}
return null;
}
return null;
}
catch (e) {
return null;
}
}
setCacheSet(setId, setCacheInfo, setData) {
this.SETS_CACHE[setId] = {
cacheInfo: setCacheInfo,
set: setData,
};
setData.card_list.forEach((card) => {
this.CARDS_CACHE[card.card_id] = card;
});
}
}
exports.ArtifactCache = ArtifactCache;