signalk-parquet
Version:
SignalK plugin and webapp that archives SK data to Parquet files with a regimen control system, advanced querying, Claude integrated AI analysis, spatial capabilities, and REST API.
127 lines • 3.66 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getCachedPaths = getCachedPaths;
exports.setCachedPaths = setCachedPaths;
exports.clearPathCache = clearPathCache;
exports.getPathCacheStats = getPathCacheStats;
exports.getCachedContexts = getCachedContexts;
exports.setCachedContexts = setCachedContexts;
exports.clearContextCache = clearContextCache;
exports.clearAllCaches = clearAllCaches;
exports.getAllCacheStats = getAllCacheStats;
const pathCache = new Map();
const contextCache = new Map();
const CACHE_TTL_MS = 60 * 1000; // 1 minute
const MAX_CACHE_SIZE = 100;
/**
* Get cached paths for a specific context and time range
*/
function getCachedPaths(context, from, to) {
const key = `${context}:${from.toString()}:${to.toString()}`;
const cached = pathCache.get(key);
if (cached && Date.now() - cached.timestamp < CACHE_TTL_MS) {
return cached.paths;
}
// Clean up expired entry
if (cached) {
pathCache.delete(key);
}
return null;
}
/**
* Cache paths for a specific context and time range
*/
function setCachedPaths(context, from, to, paths) {
const key = `${context}:${from.toString()}:${to.toString()}`;
pathCache.set(key, {
timeRange: { from: from.toString(), to: to.toString() },
paths,
timestamp: Date.now(),
});
// Clean up old entries if cache is too large
if (pathCache.size > MAX_CACHE_SIZE) {
const oldestKey = Array.from(pathCache.entries()).sort((a, b) => a[1].timestamp - b[1].timestamp)[0][0];
pathCache.delete(oldestKey);
}
}
/**
* Clear all cached paths
*/
function clearPathCache() {
pathCache.clear();
}
/**
* Get cache statistics for monitoring
*/
function getPathCacheStats() {
return {
size: pathCache.size,
maxSize: MAX_CACHE_SIZE,
ttlMs: CACHE_TTL_MS,
};
}
// ============================================================================
// Context Caching Functions
// ============================================================================
/**
* Get cached contexts for a specific time range
*/
function getCachedContexts(from, to) {
const key = `${from.toString()}:${to.toString()}`;
const cached = contextCache.get(key);
if (cached && Date.now() - cached.timestamp < CACHE_TTL_MS) {
return cached.contexts;
}
// Clean up expired entry
if (cached) {
contextCache.delete(key);
}
return null;
}
/**
* Cache contexts for a specific time range
*/
function setCachedContexts(from, to, contexts) {
const key = `${from.toString()}:${to.toString()}`;
contextCache.set(key, {
timeRange: { from: from.toString(), to: to.toString() },
contexts,
timestamp: Date.now(),
});
// Clean up old entries if cache is too large
if (contextCache.size > MAX_CACHE_SIZE) {
const oldestKey = Array.from(contextCache.entries()).sort((a, b) => a[1].timestamp - b[1].timestamp)[0][0];
contextCache.delete(oldestKey);
}
}
/**
* Clear all cached contexts
*/
function clearContextCache() {
contextCache.clear();
}
/**
* Clear all caches (paths and contexts)
*/
function clearAllCaches() {
pathCache.clear();
contextCache.clear();
}
/**
* Get all cache statistics
*/
function getAllCacheStats() {
return {
paths: {
size: pathCache.size,
maxSize: MAX_CACHE_SIZE,
ttlMs: CACHE_TTL_MS,
},
contexts: {
size: contextCache.size,
maxSize: MAX_CACHE_SIZE,
ttlMs: CACHE_TTL_MS,
},
};
}
//# sourceMappingURL=path-cache.js.map