/** * Ductape Cache Service * * Provides SDK methods for managing cache values including * fetching, setting, and deleting cache entries. * * Supports a two-tier caching strategy: * - Redis (local/fast): Primary cache layer for reads * - Remote (persistent): Backing store synced on writes/deletes/cache misses */ import { ICacheServiceConfig, ICacheValue, IFetchCacheValuesOptions, IFetchCacheValuesResult, IFetchCacheDashboardOptions, ICacheDashboardMetrics, IClearCacheValueOptions, IClearCacheValuesOptions, IClearCacheValuesResult, ISetCacheValueOptions, IGetCacheValueOptions } from './types'; /** * Custom error class for cache operations */ export declare class CacheError extends Error { code: string; originalError?: unknown; constructor(message: string, code: string, originalError?: unknown); } /** * CacheService provides methods for managing remote cache values * * @example * ```ts * import { CacheService } from '@ductape/sdk'; * * const cache = new CacheService({ * workspace_id: 'your-workspace-id', * public_key: 'your-public-key', * user_id: 'your-user-id', * token: 'your-token', * env_type: 'prd', * }); * * // Fetch cache values * const values = await cache.fetchValues({ * product: 'my-product', * cache: 'user-cache', * page: 1, * limit: 20, * }); * * // Get a specific value * const value = await cache.get({ key: 'user:123' }); * * // Set a value * await cache.set({ * product: 'my-product', * cache: 'user-cache', * key: 'user:123', * value: JSON.stringify({ name: 'John' }), * }); * * // Clear a value * await cache.clear({ key: 'user:123' }); * ``` */ export declare class CacheService { private productBuilderService; private processorApiService; private logService; private envType; private workspaceId; private publicKey; private userId; private token; private productId; /** Redis client for local caching */ private redisClient; /** Whether Redis is connected */ private redisConnected; private workspacePrivateKey; private readonly productEnv; constructor(config: ICacheServiceConfig); private resolvePE; /** * Initialize logging service */ private initializeLogService; /** * Connect to Redis for local caching * This enables the two-tier caching strategy where Redis is checked first * * @example * ```ts * await cache.connectRedis('redis://localhost:6379'); * ``` */ connectRedis(url: string): Promise; /** * Disconnect from Redis */ disconnectRedis(): Promise; /** * Check if Redis is connected */ isRedisConnected(): boolean; /** * Update service configuration (used after authentication) */ updateConfig(config: Partial): void; /** * Get user access credentials for API calls */ private getUserAccess; /** * Fetch paginated cache values * * @example * ```ts * const values = await cache.fetchValues({ * product: 'my-product', * cache: 'user-cache', * env: 'production', * page: 1, * limit: 20, * }); * ``` */ fetchValues(options: IFetchCacheValuesOptions): Promise; /** * Fetch cache dashboard metrics * * @example * ```ts * const dashboard = await cache.fetchDashboard({ * product: 'my-product', * cache: 'user-cache', * env: 'production', * }); * ``` */ fetchDashboard(options: IFetchCacheDashboardOptions): Promise; /** * Get a cache value by key * * Uses two-tier caching strategy: * 1. Check Redis cache first (fast, local) * 2. On cache miss, fetch from remote and populate Redis * * @example * ```ts * const value = await cache.get({ key: 'user:123' }); * if (value) { * console.log('Cached data:', JSON.parse(value.value)); * } * ``` */ get(options: IGetCacheValueOptions): Promise; /** * Set a cache value * * Writes to both Redis (local) and remote (persistent) cache * * @example * ```ts * await cache.set({ * product: 'my-product', * cache: 'user-cache', * key: 'user:123', * value: JSON.stringify({ name: 'John', email: 'john@example.com' }), * expiry: new Date(Date.now() + 3600000), // 1 hour from now * }); * ``` */ set(options: ISetCacheValueOptions): Promise; /** * Clear a cache value by key * * Deletes from both Redis (local) and remote (persistent) cache * * @example * ```ts * const cleared = await cache.clear({ key: 'user:123' }); * console.log('Cleared:', cleared); * ``` */ clear(options: IClearCacheValueOptions): Promise; /** * Clear all cache values for a product/cache combination * * @example * ```ts * const result = await cache.clearAll({ * product: 'my-product', * cache: 'user-cache', * env: 'production', * }); * console.log('Cleared:', result.cleared, 'values'); * ``` */ clearAll(options: IClearCacheValuesOptions): Promise; } export default CacheService;