Spaces:
Running
Running
Download src/services/pdfCache.js from hari7775/resume-server: direct link, hf CLI and curl.
- Browser
- Download file 847 Bytes
-
https://huggingface.co/spaces/hari7775/resume-server/resolve/main/src/services/pdfCache.js
- Command line
-
hf download hf://spaces/hari7775/resume-server/src/services/pdfCache.js
-
curl -L -o pdfCache.js https://huggingface.co/spaces/hari7775/resume-server/resolve/main/src/services/pdfCache.js
847 Bytes
| import crypto from 'crypto'; | |
| import { MAX_CACHE_ITEMS } from '../config.js'; | |
| // High-speed in-memory cache of pre-rendered PDF buffers (SHA-256 key -> { buffer, createdAt }). | |
| // Eviction is oldest-inserted-first once MAX_CACHE_ITEMS is reached. | |
| const pdfRamCache = new Map(); | |
| export function generateContentHash(content, metadata) { | |
| return crypto.createHash('sha256') | |
| .update(content + JSON.stringify(metadata || {})) | |
| .digest('hex'); | |
| } | |
| export function getCachedPdf(key) { | |
| return pdfRamCache.get(key); | |
| } | |
| export function cachePdf(key, buffer) { | |
| if (pdfRamCache.size >= MAX_CACHE_ITEMS) { | |
| const oldestKey = pdfRamCache.keys().next().value; | |
| pdfRamCache.delete(oldestKey); | |
| } | |
| pdfRamCache.set(key, { buffer, createdAt: Date.now() }); | |
| } | |
| export function cacheSize() { | |
| return pdfRamCache.size; | |
| } | |