criado cache m
This commit is contained in:
parent
326112a16a
commit
3c7926df4d
7 changed files with 122 additions and 1 deletions
23
dist-front/cacheMemoria.js
Normal file
23
dist-front/cacheMemoria.js
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
const _cache = {};
|
||||
const cacheM = (chave, valor, validadeSeg) => {
|
||||
const txChave = typeof chave == "string" ? chave : typeof chave == "number" ? String(chave) : encodeURIComponent(JSON.stringify(chave));
|
||||
const validade = validadeSeg && (/* @__PURE__ */ new Date()).getTime() + validadeSeg * 1e3;
|
||||
if (valor !== void 0) {
|
||||
_cache[txChave] = {
|
||||
valor,
|
||||
validade
|
||||
};
|
||||
}
|
||||
const busca = _cache[txChave];
|
||||
if (busca?.validade && busca.validade < (/* @__PURE__ */ new Date()).getTime()) {
|
||||
return void 0;
|
||||
}
|
||||
return busca?.valor;
|
||||
};
|
||||
const verCacheM = () => _cache;
|
||||
const cacheMemoria = cacheM;
|
||||
export {
|
||||
cacheM,
|
||||
cacheMemoria,
|
||||
verCacheM
|
||||
};
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
export * from "./aleatorio";
|
||||
export * from "./cacheMemoria";
|
||||
export * from "./constantes";
|
||||
export * from "./consulta";
|
||||
export * from "./ecosistema";
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue