n8n-nodes-duckduckgo-search
Version:
Integrate DuckDuckGo search seamlessly into your n8n workflows with advanced pagination and human-like behavior. Get more results without hitting rate limits.
42 lines (41 loc) • 1.21 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.pruneExpiredEntries = exports.getCacheSize = exports.clearCache = exports.setCache = exports.getCached = void 0;
const cacheStore = new Map();
function getCached(key) {
const entry = cacheStore.get(key);
if (!entry) {
return undefined;
}
if (Date.now() > entry.expiresAt) {
cacheStore.delete(key);
return undefined;
}
return entry.value;
}
exports.getCached = getCached;
function setCache(key, value, ttl) {
const expiresAt = Date.now() + ttl * 1000;
cacheStore.set(key, { value, expiresAt });
}
exports.setCache = setCache;
function clearCache() {
cacheStore.clear();
}
exports.clearCache = clearCache;
function getCacheSize() {
return cacheStore.size;
}
exports.getCacheSize = getCacheSize;
function pruneExpiredEntries() {
const now = Date.now();
let removed = 0;
for (const [key, entry] of cacheStore.entries()) {
if (now > entry.expiresAt) {
cacheStore.delete(key);
removed++;
}
}
return removed;
}
exports.pruneExpiredEntries = pruneExpiredEntries;