Files
smom-dbis-138/services/token-aggregation/src/api/middleware/cache.ts
defiQUG 1511f33857 chore: update DBIS contracts and integrate EIP-712 helper
- Updated DBIS_ConversionRouter and DBIS_SettlementRouter to utilize IDBIS_EIP712Helper for EIP-712 hashing and signature recovery, improving stack depth management.
- Refactored minting logic in DBIS_GRU_MintController to streamline recipient processing.
- Enhanced BUILD_NOTES.md with updated build instructions and test coverage details.
- Added new functions in DBIS_SignerRegistry for duplicate signer checks and active signer validation.
- Introduced a new submodule, DBIS_EIP712Helper, to encapsulate EIP-712 related functionalities.

Made-with: Cursor
2026-03-04 02:00:09 -08:00

47 lines
1.0 KiB
TypeScript

import { Request, Response, NextFunction } from 'express';
interface CacheEntry {
data: unknown;
expiresAt: number;
}
const cache = new Map<string, CacheEntry>();
const DEFAULT_TTL = 60 * 1000; // 1 minute
export function cacheMiddleware(ttl: number = DEFAULT_TTL) {
return (req: Request, res: Response, next: NextFunction) => {
const key = `${req.method}:${req.originalUrl}`;
const cached = cache.get(key);
if (cached && cached.expiresAt > Date.now()) {
return res.json(cached.data);
}
// Store original json method
const originalJson = res.json.bind(res);
// Override json method to cache response
res.json = function (body: unknown) {
cache.set(key, {
data: body,
expiresAt: Date.now() + ttl,
});
return originalJson(body);
};
next();
};
}
export function clearCache(): void {
cache.clear();
}
export function clearCacheForPattern(pattern: string): void {
for (const key of cache.keys()) {
if (key.includes(pattern)) {
cache.delete(key);
}
}
}