implementado typescript 7
This commit is contained in:
parent
cd4ea4d36b
commit
e9a323f18c
80 changed files with 5711 additions and 2455 deletions
27
dist-front/cacheMemoria.js
Normal file
27
dist-front/cacheMemoria.js
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
/** gerar uma função de cache para uso em memoria */
|
||||
const _cache = {};
|
||||
globalThis.cacheMemoria_cache = _cache;
|
||||
export const cacheM = (chave, valor, validadeSeg) => {
|
||||
// converte a chave e string
|
||||
const txChave = typeof chave == "string"
|
||||
? chave
|
||||
: typeof chave == "number"
|
||||
? String(chave)
|
||||
: encodeURIComponent(JSON.stringify(chave));
|
||||
const validade = validadeSeg && new Date().getTime() + validadeSeg * 1000;
|
||||
if (valor !== undefined) {
|
||||
_cache[txChave] = {
|
||||
valor,
|
||||
validade,
|
||||
};
|
||||
}
|
||||
const busca = _cache[txChave];
|
||||
if (busca?.validade && busca.validade < new Date().getTime()) {
|
||||
return undefined;
|
||||
}
|
||||
return busca?.valor;
|
||||
};
|
||||
export const verCacheM = () => _cache;
|
||||
export const cacheMemoria = cacheM;
|
||||
/** para uso fixo dentro de uma função, trava a chave */
|
||||
export const cacheMFixo = (chave) => (valor) => cacheM(chave, valor);
|
||||
Loading…
Add table
Add a link
Reference in a new issue