mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-25 01:48:39 -06:00
add: hGet and hSet on LocalCache
This commit is contained in:
parent
0b40583fa8
commit
9a6d4a8e44
37
src/cache/localcache.ts
vendored
37
src/cache/localcache.ts
vendored
@ -1,8 +1,11 @@
|
|||||||
import { ICache } from '@api/abstract/abstract.cache';
|
import { ICache } from '@api/abstract/abstract.cache';
|
||||||
import { CacheConf, CacheConfLocal, ConfigService } from '@config/env.config';
|
import { CacheConf, CacheConfLocal, ConfigService } from '@config/env.config';
|
||||||
import NodeCache from 'node-cache';
|
import NodeCache from 'node-cache';
|
||||||
|
import { BufferJSON } from 'baileys';
|
||||||
|
import { Logger } from '@config/logger.config';
|
||||||
|
|
||||||
export class LocalCache implements ICache {
|
export class LocalCache implements ICache {
|
||||||
|
private readonly logger = new Logger('LocalCache');
|
||||||
private conf: CacheConfLocal;
|
private conf: CacheConfLocal;
|
||||||
static localCache = new NodeCache();
|
static localCache = new NodeCache();
|
||||||
|
|
||||||
@ -45,14 +48,36 @@ export class LocalCache implements ICache {
|
|||||||
return `${this.module}:${key}`;
|
return `${this.module}:${key}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
async hGet() {
|
async hGet(key: string, field: string) {
|
||||||
console.log('hGet not implemented');
|
try {
|
||||||
return null
|
const data = LocalCache.localCache.get(this.buildKey(key)) as Object;
|
||||||
|
|
||||||
|
if (data && field in data) {
|
||||||
|
return JSON.parse(data[field], BufferJSON.reviver);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
} catch (error) {
|
||||||
|
this.logger.error(error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async hSet() {
|
async hSet(key: string, field: string, value: any) {
|
||||||
console.log('hSet not implemented');
|
try {
|
||||||
return null
|
const json = JSON.stringify(value, BufferJSON.replacer);
|
||||||
|
|
||||||
|
let hash = LocalCache.localCache.get(this.buildKey(key));
|
||||||
|
|
||||||
|
if (!hash) {
|
||||||
|
hash = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
hash[field] = json;
|
||||||
|
LocalCache.localCache.set(key, hash);
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
this.logger.error(error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async hDelete() {
|
async hDelete() {
|
||||||
|
Loading…
Reference in New Issue
Block a user