@push.rocks/smartproxy
Version:
A powerful proxy package with unified route-based configuration for high traffic management. Features include SSL/TLS support, flexible routing patterns, WebSocket handling, advanced security options, and automatic ACME certificate management.
96 lines (95 loc) • 3 kB
TypeScript
import type { IRouteContext } from '../../core/models/route-context.js';
import type { ILogger } from './models/types.js';
/**
* Function cache for NetworkProxy function-based targets
*
* This cache improves performance for function-based targets by storing
* the results of function evaluations and reusing them for similar contexts.
*/
export declare class FunctionCache {
private hostCache;
private portCache;
private maxCacheSize;
private defaultTtl;
private logger;
private cleanupInterval;
/**
* Creates a new function cache
*
* @param logger Logger for debug output
* @param options Cache options
*/
constructor(logger: ILogger, options?: {
maxCacheSize?: number;
defaultTtl?: number;
});
/**
* Compute a hash for a context object
* This is used to identify similar contexts for caching
*
* @param context The route context to hash
* @param functionId Identifier for the function (usually route name or ID)
* @returns A string hash
*/
private computeContextHash;
/**
* Get cached host result for a function and context
*
* @param context Route context
* @param functionId Identifier for the function
* @returns Cached host value or undefined if not found
*/
getCachedHost(context: IRouteContext, functionId: string): string | string[] | undefined;
/**
* Get cached port result for a function and context
*
* @param context Route context
* @param functionId Identifier for the function
* @returns Cached port value or undefined if not found
*/
getCachedPort(context: IRouteContext, functionId: string): number | undefined;
/**
* Store a host function result in the cache
*
* @param context Route context
* @param functionId Identifier for the function
* @param value Host value to cache
* @param ttl Optional TTL in milliseconds
*/
cacheHost(context: IRouteContext, functionId: string, value: string | string[], ttl?: number): void;
/**
* Store a port function result in the cache
*
* @param context Route context
* @param functionId Identifier for the function
* @param value Port value to cache
* @param ttl Optional TTL in milliseconds
*/
cachePort(context: IRouteContext, functionId: string, value: number, ttl?: number): void;
/**
* Remove expired entries from the cache
*/
private cleanupCache;
/**
* Prune oldest entries from a cache map
* Used when the cache exceeds the maximum size
*
* @param cache The cache map to prune
*/
private pruneOldestEntries;
/**
* Get current cache stats
*/
getStats(): {
hostCacheSize: number;
portCacheSize: number;
};
/**
* Clear all cached entries
*/
clearCache(): void;
/**
* Destroy the cache and cleanup resources
*/
destroy(): void;
}