@contiva/sap-integration-suite-client
Version:
SAP Cloud Platform Integration API Client
94 lines (93 loc) • 2.96 kB
TypeScript
/**
* Cache configuration constants and utilities
*
* FIX P3-2: TTL values are now configurable via configureCacheTTL()
* This allows backends to pass their own TTL configuration instead of using hardcoded defaults.
*
* @module cache-config
*/
/**
* Current (potentially customized) Cache TTL values
* FIX P3-2: Mutable to allow runtime configuration
*/
export declare let CACHE_TTL: {
STANDARD: number;
};
/**
* Current (potentially customized) Revalidation time values
* FIX P3-2: Mutable to allow runtime configuration
*/
export declare let REVALIDATE_AFTER: {
STANDARD: number;
RUNTIME: number;
};
/**
* Cache TTL configuration options
*/
export interface CacheTTLConfig {
/** TTL for standard endpoints in seconds (default: 30 days) */
standardTTL?: number;
/** Revalidation time for standard endpoints in seconds (default: 1 hour) */
standardRevalidate?: number;
/** Revalidation time for runtime endpoints in seconds (default: 5 minutes) */
runtimeRevalidate?: number;
}
/**
* Configures cache TTL values at runtime
*
* FIX P3-2: Allows backends to pass their own TTL configuration
* Call this during initialization before making any cache operations.
*
* @param config - TTL configuration options
*
* @example
* ```typescript
* import { configureCacheTTL } from '@contiva/sap-integration-suite-client';
*
* // Use backend's configured TTL values
* configureCacheTTL({
* standardTTL: parseInt(process.env.CACHE_TTL_SECONDS, 10) || 2592000,
* standardRevalidate: parseInt(process.env.CACHE_REVALIDATE_SECONDS, 10) || 3600,
* runtimeRevalidate: parseInt(process.env.CACHE_RUNTIME_REVALIDATE_SECONDS, 10) || 300,
* });
* ```
*/
export declare function configureCacheTTL(config: CacheTTLConfig): void;
/**
* Resets cache TTL values to defaults
* Useful for testing or when reconfiguration is needed
*/
export declare function resetCacheTTL(): void;
/**
* Gets current TTL configuration (for debugging/logging)
*/
export declare function getCacheTTLConfig(): {
ttl: typeof CACHE_TTL;
revalidate: typeof REVALIDATE_AFTER;
};
/**
* Background revalidation timeout in milliseconds
* Increased from 5s to 30s to allow queue processing more time to complete
*/
export declare const REVALIDATION_TIMEOUT_MS = 30000;
/**
* Checks if a URL should be cached
*
* @param url - The URL to check
* @returns true if the URL is cacheable, false otherwise
*/
export declare function isCacheableUrl(url: string): boolean;
/**
* Determines if a URL is a runtime API that needs shorter revalidation
*
* @param url - The URL to check
* @returns true if it's a runtime API, false otherwise
*/
export declare function isRuntimeApi(url: string): boolean;
/**
* Gets the appropriate revalidation time for a URL
*
* @param url - The URL to get revalidation time for
* @returns Revalidation time in seconds
*/
export declare function getRevalidationTime(url: string): number;