fleeta-api-lib
Version:
A comprehensive library for fleet management applications - API, Auth, Device management
206 lines • 5.51 kB
TypeScript
/**
* GPS Data Caching Utilities
* Provides caching functionality for GPS device data with memory management
*/
import type { DeviceGpsInfo } from '../../gps-websocket/types';
/**
* GPS Data Cache statistics interface
*/
interface GpsCacheStats {
totalEntries: number;
memoryUsageBytes: number;
oldestEntry: Date | null;
newestEntry: Date | null;
hitCount: number;
missCount: number;
hitRatio: number;
}
/**
* GPS Data Cache configuration interface
*/
interface GpsCacheConfig {
maxEntries: number;
maxAge: number;
enableCompression: boolean;
autoCleanup: boolean;
cleanupInterval: number;
}
/**
* GPS Data Cache class
* Manages caching of GPS device data with LRU eviction and automatic cleanup
*/
export declare class GpsDataCache {
private cache;
private accessOrder;
private config;
private stats;
private cleanupTimer;
/**
* Create GPS data cache instance
* @param config - Cache configuration
*/
constructor(config?: Partial<GpsCacheConfig>);
/**
* Store GPS data in cache
* @param key - Cache key
* @param data - GPS device data
* @param source - Data source
*/
set(key: string, data: DeviceGpsInfo[], source?: 'websocket' | 'api' | 'manual'): void;
/**
* Retrieve GPS data from cache
* @param key - Cache key
* @returns Cached GPS data or null
*/
get(key: string): DeviceGpsInfo[] | null;
/**
* Check if key exists in cache and is not expired
* @param key - Cache key
* @returns True if key exists and is valid
*/
has(key: string): boolean;
/**
* Delete entry from cache
* @param key - Cache key
*/
delete(key: string): boolean;
/**
* Clear all cache entries
*/
clear(): void;
/**
* Get cache statistics
* @returns Cache statistics
*/
getStats(): GpsCacheStats;
/**
* Get all cache keys
* @returns Array of cache keys
*/
keys(): string[];
/**
* Get cached data for multiple keys
* @param keys - Array of cache keys
* @returns Map of key to cached data
*/
getMultiple(keys: string[]): Map<string, DeviceGpsInfo[]>;
/**
* Set cache configuration
* @param newConfig - New configuration
*/
updateConfig(newConfig: Partial<GpsCacheConfig>): void;
/**
* Manually trigger cache cleanup
*/
cleanup(): void;
/**
* Destroy cache and cleanup resources
*/
destroy(): void;
/**
* Check if cache entry is expired
* @param entry - Cache entry
* @returns True if expired
*/
private isExpired;
/**
* Enforce maximum cache entries by removing oldest
*/
private enforceMaxEntries;
/**
* Move key to end of access order (most recently used)
* @param key - Cache key
*/
private moveToEnd;
/**
* Remove key from access order
* @param key - Cache key
*/
private removeFromAccessOrder;
/**
* Update cache statistics
*/
private updateStats;
/**
* Update hit ratio
*/
private updateHitRatio;
/**
* Calculate approximate memory usage
* @returns Memory usage in bytes (approximate)
*/
private calculateMemoryUsage;
/**
* Start automatic cache cleanup
*/
private startAutoCleanup;
/**
* Stop automatic cache cleanup
*/
private stopAutoCleanup;
/**
* Compress GPS data (simplified - in real implementation, use proper compression)
* @param data - GPS device data
* @returns Compressed data
*/
private compressData;
/**
* Decompress GPS data
* @param data - Compressed GPS device data
* @returns Decompressed data
*/
private decompressData;
}
/**
* Create a GPS data cache with default configuration
* @param config - Optional cache configuration
* @returns GPS data cache instance
*/
export declare function createGpsDataCache(config?: Partial<GpsCacheConfig>): GpsDataCache;
/**
* Generate cache key for GPS data
* @param userEmail - User email
* @param psnList - List of PSNs
* @param filter - Additional filter criteria
* @returns Cache key string
*/
export declare function generateCacheKey(userEmail: string, psnList?: string[], filter?: string): string;
/**
* Cache key generators for different data types
*/
export declare const CacheKeys: {
/**
* Generate key for multi live view data
*/
multiLiveView: (userEmail: string, psnList: string[]) => string;
/**
* Generate key for user devices data
*/
myDevices: (userEmail: string) => string;
/**
* Generate key for zone data
*/
zone: (userEmail: string, sw: string, ne: string) => string;
/**
* Generate key for specific device data
*/
specificDevice: (userEmail: string, psn: string) => string;
/**
* Generate key for filtered data
*/
filtered: (userEmail: string, filterHash: string) => string;
/**
* Generate key for zone no auth data
*/
zoneNoAuth: (sw: string, ne: string) => string;
/**
* Generate key for zone all devices data
*/
zoneAllDevices: (userEmail: string, sw: string, ne: string) => string;
/**
* Generate key for group zone data
*/
groupZone: (userEmail: string, sw: string, ne: string, groupIdList: string[], type: "my" | "all") => string;
};
export {};
//# sourceMappingURL=caching.d.ts.map