digital-samba-mcp-server
Version:
Digital Samba MCP Server - Model Context Protocol server for Digital Samba's video conferencing API
169 lines • 5.11 kB
TypeScript
/**
* Digital Samba MCP Server - Cache Module
*
* This module provides caching functionality for the Digital Samba MCP Server.
* It implements a flexible caching system for API responses, reducing load on
* the Digital Samba API and improving response times for clients.
*
* Features include:
* - Configurable TTL (Time-To-Live) for cached responses
* - Memory-based cache storage
* - Optional Redis-based storage for distributed deployments
* - Cache invalidation strategies
* - Support for conditional requests (ETag, If-Modified-Since)
*
* @module cache
* @author Digital Samba Team
* @version 0.1.0
*/
/**
* Cache options interface
*/
export interface CacheOptions {
/** Default TTL in milliseconds */
ttl: number;
/** Maximum number of items to store */
maxItems?: number;
/** Whether to use ETag for conditional requests */
useEtag?: boolean;
/** Function to generate cache keys */
keyGenerator?: (namespace: string, id: string) => string;
/** Custom serialization function */
serializer?: (value: any) => string;
/** Custom deserialization function */
deserializer?: (value: string) => any;
}
/**
* Cache entry interface
*/
interface CacheEntry<T> {
/** Cached value */
value: T;
/** Expiration timestamp */
expires: number;
/** ETag for conditional requests */
etag?: string;
/** Last modified timestamp */
lastModified?: Date;
}
/**
* Default cache options
*/
export declare const defaultCacheOptions: CacheOptions;
/**
* Memory-based cache implementation
*/
export declare class MemoryCache<T = any> {
private cache;
private options;
/**
* Creates a new MemoryCache
* @param options Cache options
*/
constructor(options?: Partial<CacheOptions>);
/**
* Generates an ETag for a value
* @param value Value to generate ETag for
* @returns ETag string
*/
private generateEtag;
/**
* Starts the cleanup interval to remove expired items
*/
private startCleanupInterval;
/**
* Cleans up expired cache entries
*/
cleanup(): void;
/**
* Sets a value in the cache
* @param namespace Cache namespace
* @param id Item identifier
* @param value Value to cache
* @param ttl Optional TTL override
* @returns The cached entry
*/
set(namespace: string, id: string, value: T, ttl?: number): CacheEntry<T>;
/**
* Gets a value from the cache
* @param namespace Cache namespace
* @param id Item identifier
* @returns The cached entry or undefined if not found or expired
*/
get(namespace: string, id: string): CacheEntry<T> | undefined;
/**
* Deletes a value from the cache
* @param namespace Cache namespace
* @param id Item identifier
* @returns Whether the item was deleted
*/
delete(namespace: string, id: string): boolean;
/**
* Invalidates a specific cache entry in a namespace
* @param namespace Cache namespace
* @param id Item identifier
* @returns Whether the item was invalidated
*/
invalidate(namespace: string, id: string): boolean;
/**
* Invalidates all items in a namespace
* @param namespace Cache namespace
* @returns Number of items invalidated
*/
invalidateNamespace(namespace: string): number;
/**
* Checks if a value is fresh based on conditional headers
* @param namespace Cache namespace
* @param id Item identifier
* @param etag ETag to compare
* @param modifiedSince Last-Modified date to compare
* @returns Whether the cached value is considered fresh
*/
isFresh(namespace: string, id: string, etag?: string, modifiedSince?: Date): boolean;
/**
* Evicts the oldest item from the cache
* @returns Whether an item was evicted
*/
private evictOldest;
/**
* Clears the entire cache
*/
clear(): void;
/**
* Gets cache statistics
* @returns Cache statistics
*/
getStats(): {
totalItems: number;
validItems: number;
expiredItems: number;
maxItems: number;
};
}
/**
* Redis-backed cache implementation
* This implementation uses Redis for storage, making it suitable for distributed deployments.
* Note: This is a placeholder for the Redis implementation.
* The actual implementation would use a Redis client library.
*/
export declare class RedisCache<T = any> {
constructor(options?: Partial<CacheOptions>);
}
/**
* Create a caching middleware for Express
* This is a placeholder function for a potential Express middleware
*/
export declare function createCacheMiddleware(options?: Partial<CacheOptions>): {
cache: MemoryCache<any>;
middleware: (namespace: string) => (req: any, res: any, next: any) => void;
};
/**
* Exports the default cache
*/
declare const _default: {
MemoryCache: typeof MemoryCache;
RedisCache: typeof RedisCache;
createCacheMiddleware: typeof createCacheMiddleware;
};
export default _default;
//# sourceMappingURL=cache.d.ts.map