@ixily/activ
Version:
Alpha Capture Trade Idea Verification. Blockchain ownership proven trade ideas and strategies.
73 lines • 3.07 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.CacheService = void 0;
const modules_1 = require("../../modules");
const version_contract_db_json_1 = require("../../../version-contract-db.json");
class CacheService {
static async getData(params) {
const chain = params.contract !== undefined
? '' + (await params.contract.signer?.getChainId())
: 'public';
const cacheKey = params.key + '_' + version_contract_db_json_1.contractDbVersion + '_chain_' + chain;
// console.log(chain)
if (CacheService.cacheIsEnabled) {
// console.log('CacheService (pre result)')
const result = await modules_1.CacheStorageModule.getData(cacheKey);
// console.log('CacheService (result)', result)
if (result !== undefined) {
const response = {
data: result,
fromCache: true,
};
return response;
// console.log('CacheService (cacheKey)', cacheKey)
// console.log('CacheService (fromCache)', fromCache)
// console.log('CacheService (result)', { data, fromCache })
}
}
// console.log('CacheService (pre data)')
const data = await params.init();
// console.log('CacheService (data)', data)
if (data !== undefined &&
CacheService.cacheIsEnabled &&
!params.unsave) {
delete data.unsave;
// console.log('pre CacheStorageModule.addData')
await modules_1.CacheStorageModule.addData(cacheKey, data, params.expirationInSeconds);
// console.log('post CacheStorageModule.addData')
}
const response = {
data,
fromCache: false,
};
return response;
}
static async updateData(payload) {
try {
const chain = payload.contract !== undefined
? '' + (await payload.contract.signer?.getChainId())
: 'public';
const cacheKey = payload?.key + '_' + version_contract_db_json_1.contractDbVersion + '_chain_' + chain;
if (!payload?.forceToAdd && CacheService.cacheIsEnabled) {
await modules_1.CacheStorageModule.updateData(cacheKey, payload?.data, payload?.expirationInSeconds);
}
if (payload?.forceToAdd && CacheService.cacheIsEnabled) {
await modules_1.CacheStorageModule.addData(cacheKey, payload?.data, payload?.expirationInSeconds);
}
}
catch (err) {
console.log('CacheService ERROR (updateData)', err?.message);
}
}
static async resetData() {
try {
await modules_1.CacheStorageModule.resetData();
}
catch (err) {
console.log('CacheService ERROR (removeData)', err?.message);
}
}
}
exports.CacheService = CacheService;
CacheService.cacheIsEnabled = true;
//# sourceMappingURL=cache.tool.js.map