fixed cache keys
This commit is contained in:
parent
db3aa9c330
commit
19dfda2392
13 changed files with 286 additions and 221 deletions
|
|
@ -6,6 +6,7 @@ import {
|
|||
type HandlerConfigWithSchedule,
|
||||
} from '@stock-bot/types';
|
||||
import { fetch } from '@stock-bot/utils';
|
||||
import { createNamespacedCache } from '@stock-bot/cache';
|
||||
import type { IServiceContainer } from '../types/service-container';
|
||||
import type { ExecutionContext, IHandler } from '../types/types';
|
||||
|
||||
|
|
@ -126,6 +127,14 @@ export abstract class BaseHandler implements IHandler {
|
|||
return this.mongodb.collection(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a sub-namespaced cache for specific operations
|
||||
* Example: handler 'webshare' creates namespace 'webshare:api' -> keys will be 'cache:webshare:api:*'
|
||||
*/
|
||||
protected createNamespacedCache(subNamespace: string) {
|
||||
return createNamespacedCache(this.cache, `${this.handlerName}:${subNamespace}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set cache with handler-prefixed key
|
||||
*/
|
||||
|
|
@ -133,7 +142,7 @@ export abstract class BaseHandler implements IHandler {
|
|||
if (!this.cache) {
|
||||
return;
|
||||
}
|
||||
return this.cache.set(`${this.handlerName}:${key}`, value, ttl);
|
||||
return this.cache.set(`cache:${this.handlerName}:${key}`, value, ttl);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -143,7 +152,7 @@ export abstract class BaseHandler implements IHandler {
|
|||
if (!this.cache) {
|
||||
return null;
|
||||
}
|
||||
return this.cache.get(`${this.handlerName}:${key}`);
|
||||
return this.cache.get(`cache:${this.handlerName}:${key}`);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -153,7 +162,7 @@ export abstract class BaseHandler implements IHandler {
|
|||
if (!this.cache) {
|
||||
return;
|
||||
}
|
||||
return this.cache.del(`${this.handlerName}:${key}`);
|
||||
return this.cache.del(`cache:${this.handlerName}:${key}`);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue