@naman_deep_singh/cache 1.5.0 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/cjs/adapters/index.js +19 -0
- package/dist/cjs/adapters/memcache/MemcacheCache.js +10 -11
- package/dist/cjs/adapters/memcache/index.js +2 -2
- package/dist/cjs/adapters/memory/MemoryCache.js +14 -15
- package/dist/cjs/adapters/memory/index.js +2 -2
- package/dist/cjs/adapters/redis/RedisCache.js +15 -16
- package/dist/cjs/adapters/redis/index.js +2 -2
- package/dist/cjs/core/BaseCache.js +3 -4
- package/dist/cjs/core/factory.js +10 -13
- package/dist/cjs/core/index.js +19 -0
- package/dist/cjs/core/interfaces/index.js +16 -0
- package/dist/cjs/errors/index.js +18 -5
- package/dist/cjs/index.js +25 -24
- package/dist/cjs/middleware/express/index.js +15 -5
- package/dist/cjs/middleware/index.js +17 -0
- package/dist/cjs/session/SessionStore.js +16 -17
- package/dist/cjs/session/index.js +15 -3
- package/dist/esm/adapters/index.js +3 -0
- package/dist/esm/adapters/memcache/MemcacheCache.js +2 -3
- package/dist/esm/adapters/memcache/index.js +1 -1
- package/dist/esm/adapters/memory/MemoryCache.js +2 -3
- package/dist/esm/adapters/memory/index.js +1 -1
- package/dist/esm/adapters/redis/RedisCache.js +2 -3
- package/dist/esm/adapters/redis/index.js +1 -1
- package/dist/esm/core/BaseCache.js +1 -2
- package/dist/esm/core/factory.js +2 -5
- package/dist/esm/core/index.js +3 -0
- package/dist/esm/core/interfaces/index.js +2 -1
- package/dist/esm/errors/index.js +3 -2
- package/dist/esm/index.js +11 -13
- package/dist/esm/middleware/express/index.js +1 -1
- package/dist/esm/middleware/index.js +1 -0
- package/dist/esm/session/SessionStore.js +1 -2
- package/dist/esm/session/index.js +1 -1
- package/dist/types/adapters/index.d.ts +3 -0
- package/dist/types/adapters/memcache/MemcacheCache.d.ts +2 -2
- package/dist/types/adapters/memcache/index.d.ts +1 -1
- package/dist/types/adapters/memory/MemoryCache.d.ts +2 -2
- package/dist/types/adapters/memory/index.d.ts +1 -1
- package/dist/types/adapters/redis/RedisCache.d.ts +2 -2
- package/dist/types/adapters/redis/index.d.ts +1 -1
- package/dist/types/core/BaseCache.d.ts +2 -2
- package/dist/types/core/factory.d.ts +2 -2
- package/dist/types/core/index.d.ts +3 -0
- package/dist/types/core/interfaces/ICache.d.ts +1 -1
- package/dist/types/core/interfaces/ISession.d.ts +1 -1
- package/dist/types/core/interfaces/index.d.ts +2 -2
- package/dist/types/errors/CacheError.d.ts +1 -1
- package/dist/types/errors/index.d.ts +2 -1
- package/dist/types/index.d.ts +6 -10
- package/dist/types/middleware/express/cacheMiddleware.d.ts +2 -2
- package/dist/types/middleware/express/index.d.ts +1 -1
- package/dist/types/middleware/index.d.ts +1 -0
- package/dist/types/session/SessionStore.d.ts +2 -2
- package/dist/types/session/index.d.ts +1 -2
- package/package.json +3 -3
- package/dist/cjs/adapters/memcache/MemcacheCache.d.ts +0 -18
- package/dist/cjs/adapters/memcache/index.d.ts +0 -1
- package/dist/cjs/adapters/memory/MemoryCache.d.ts +0 -63
- package/dist/cjs/adapters/memory/index.d.ts +0 -1
- package/dist/cjs/adapters/redis/RedisCache.d.ts +0 -67
- package/dist/cjs/adapters/redis/index.d.ts +0 -1
- package/dist/cjs/core/BaseCache.d.ts +0 -78
- package/dist/cjs/core/factory.d.ts +0 -16
- package/dist/cjs/core/interfaces/ICache.d.ts +0 -58
- package/dist/cjs/core/interfaces/ISession.d.ts +0 -30
- package/dist/cjs/core/interfaces/index.d.ts +0 -2
- package/dist/cjs/errors/CacheError.d.ts +0 -12
- package/dist/cjs/errors/cacheErrorCodes.d.ts +0 -22
- package/dist/cjs/errors/index.d.ts +0 -1
- package/dist/cjs/index.d.ts +0 -10
- package/dist/cjs/middleware/express/cacheMiddleware.d.ts +0 -22
- package/dist/cjs/middleware/express/index.d.ts +0 -1
- package/dist/cjs/session/SessionStore.d.ts +0 -57
- package/dist/cjs/session/index.d.ts +0 -2
- package/dist/cjs/types.d.ts +0 -102
- package/dist/esm/adapters/memcache/MemcacheCache.d.ts +0 -18
- package/dist/esm/adapters/memcache/index.d.ts +0 -1
- package/dist/esm/adapters/memory/MemoryCache.d.ts +0 -63
- package/dist/esm/adapters/memory/index.d.ts +0 -1
- package/dist/esm/adapters/redis/RedisCache.d.ts +0 -67
- package/dist/esm/adapters/redis/index.d.ts +0 -1
- package/dist/esm/core/BaseCache.d.ts +0 -78
- package/dist/esm/core/factory.d.ts +0 -16
- package/dist/esm/core/interfaces/ICache.d.ts +0 -58
- package/dist/esm/core/interfaces/ISession.d.ts +0 -30
- package/dist/esm/core/interfaces/index.d.ts +0 -2
- package/dist/esm/errors/CacheError.d.ts +0 -12
- package/dist/esm/errors/cacheErrorCodes.d.ts +0 -22
- package/dist/esm/errors/index.d.ts +0 -1
- package/dist/esm/index.d.ts +0 -10
- package/dist/esm/middleware/express/cacheMiddleware.d.ts +0 -22
- package/dist/esm/middleware/express/index.d.ts +0 -1
- package/dist/esm/session/SessionStore.d.ts +0 -57
- package/dist/esm/session/index.d.ts +0 -2
- package/dist/esm/types.d.ts +0 -102
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import type { BatchResult, CacheConfig, CacheStats, HealthCheckResponse } from '../types';
|
|
2
|
-
import type { ICache } from './interfaces';
|
|
3
|
-
/**
|
|
4
|
-
* Abstract base class for all cache adapters
|
|
5
|
-
*/
|
|
6
|
-
export declare abstract class BaseCache<T = unknown> implements ICache<T> {
|
|
7
|
-
protected config: CacheConfig;
|
|
8
|
-
protected readonly namespace: string;
|
|
9
|
-
protected readonly ttl: number;
|
|
10
|
-
protected stats: CacheStats;
|
|
11
|
-
constructor(config: CacheConfig);
|
|
12
|
-
/**
|
|
13
|
-
* Build full key with namespace prefix
|
|
14
|
-
*/
|
|
15
|
-
protected buildKey(key: string): string;
|
|
16
|
-
/**
|
|
17
|
-
* Deserialize string to object
|
|
18
|
-
*/
|
|
19
|
-
protected deserialize(data: string): T;
|
|
20
|
-
/**
|
|
21
|
-
* Serialize object to string
|
|
22
|
-
*/
|
|
23
|
-
protected serialize(value: T): string;
|
|
24
|
-
/**
|
|
25
|
-
* Track cache hit
|
|
26
|
-
*/
|
|
27
|
-
protected recordHit(): void;
|
|
28
|
-
/**
|
|
29
|
-
* Track cache miss
|
|
30
|
-
*/
|
|
31
|
-
protected recordMiss(): void;
|
|
32
|
-
/**
|
|
33
|
-
* Track cache set
|
|
34
|
-
*/
|
|
35
|
-
protected recordSet(): void;
|
|
36
|
-
/**
|
|
37
|
-
* Track cache delete
|
|
38
|
-
*/
|
|
39
|
-
protected recordDelete(): void;
|
|
40
|
-
/**
|
|
41
|
-
* Reset statistics
|
|
42
|
-
*/
|
|
43
|
-
protected resetStats(): void;
|
|
44
|
-
/**
|
|
45
|
-
* Get cache statistics
|
|
46
|
-
*/
|
|
47
|
-
getStats(): Promise<CacheStats>;
|
|
48
|
-
/**
|
|
49
|
-
* Abstract methods - must be implemented by subclasses
|
|
50
|
-
*/
|
|
51
|
-
abstract get(key: string): Promise<T | null>;
|
|
52
|
-
abstract set(key: string, value: T, ttl?: number): Promise<void>;
|
|
53
|
-
abstract delete(key: string): Promise<boolean>;
|
|
54
|
-
abstract exists(key: string): Promise<boolean>;
|
|
55
|
-
abstract clear(): Promise<void>;
|
|
56
|
-
abstract isAlive(): Promise<HealthCheckResponse>;
|
|
57
|
-
abstract close(): Promise<void>;
|
|
58
|
-
/**
|
|
59
|
-
* Default implementation for getMultiple
|
|
60
|
-
*/
|
|
61
|
-
getMultiple(keys: string[]): Promise<BatchResult<T>>;
|
|
62
|
-
/**
|
|
63
|
-
* Default implementation for setMultiple
|
|
64
|
-
*/
|
|
65
|
-
setMultiple(data: Record<string, T>, ttl?: number): Promise<void>;
|
|
66
|
-
/**
|
|
67
|
-
* Default implementation for deleteMultiple
|
|
68
|
-
*/
|
|
69
|
-
deleteMultiple(keys: string[]): Promise<number>;
|
|
70
|
-
/**
|
|
71
|
-
* Default implementation for increment
|
|
72
|
-
*/
|
|
73
|
-
increment(key: string, amount?: number): Promise<number>;
|
|
74
|
-
/**
|
|
75
|
-
* Default implementation for decrement
|
|
76
|
-
*/
|
|
77
|
-
decrement(key: string, amount?: number): Promise<number>;
|
|
78
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { CacheConfig } from '../types';
|
|
2
|
-
import type { ICache } from './interfaces';
|
|
3
|
-
/**
|
|
4
|
-
* Factory for creating cache instances
|
|
5
|
-
*/
|
|
6
|
-
export declare class CacheFactory {
|
|
7
|
-
/**
|
|
8
|
-
* Create a cache instance based on configuration
|
|
9
|
-
*/
|
|
10
|
-
static create<T = unknown>(config: CacheConfig): ICache<T>;
|
|
11
|
-
/**
|
|
12
|
-
* Create a cache with fallback support
|
|
13
|
-
* If primary adapter fails to connect, falls back to memory cache
|
|
14
|
-
*/
|
|
15
|
-
static createWithFallback<T = unknown>(config: CacheConfig): Promise<ICache<T>>;
|
|
16
|
-
}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import type { BatchResult, CacheStats, HealthCheckResponse } from '../../types';
|
|
2
|
-
/**
|
|
3
|
-
* Main cache interface - defines all cache operations
|
|
4
|
-
*/
|
|
5
|
-
export interface ICache<T = unknown> {
|
|
6
|
-
/**
|
|
7
|
-
* Get a value from cache
|
|
8
|
-
*/
|
|
9
|
-
get(key: string): Promise<T | null>;
|
|
10
|
-
/**
|
|
11
|
-
* Set a value in cache
|
|
12
|
-
*/
|
|
13
|
-
set(key: string, value: T, ttl?: number): Promise<void>;
|
|
14
|
-
/**
|
|
15
|
-
* Delete a value from cache
|
|
16
|
-
*/
|
|
17
|
-
delete(key: string): Promise<boolean>;
|
|
18
|
-
/**
|
|
19
|
-
* Check if key exists
|
|
20
|
-
*/
|
|
21
|
-
exists(key: string): Promise<boolean>;
|
|
22
|
-
/**
|
|
23
|
-
* Clear all cache entries
|
|
24
|
-
*/
|
|
25
|
-
clear(): Promise<void>;
|
|
26
|
-
/**
|
|
27
|
-
* Get multiple values at once
|
|
28
|
-
*/
|
|
29
|
-
getMultiple(keys: string[]): Promise<BatchResult<T>>;
|
|
30
|
-
/**
|
|
31
|
-
* Set multiple values at once
|
|
32
|
-
*/
|
|
33
|
-
setMultiple(data: Record<string, T>, ttl?: number): Promise<void>;
|
|
34
|
-
/**
|
|
35
|
-
* Delete multiple keys at once
|
|
36
|
-
*/
|
|
37
|
-
deleteMultiple(keys: string[]): Promise<number>;
|
|
38
|
-
/**
|
|
39
|
-
* Increment a numeric value
|
|
40
|
-
*/
|
|
41
|
-
increment(key: string, amount?: number): Promise<number>;
|
|
42
|
-
/**
|
|
43
|
-
* Decrement a numeric value
|
|
44
|
-
*/
|
|
45
|
-
decrement(key: string, amount?: number): Promise<number>;
|
|
46
|
-
/**
|
|
47
|
-
* Get cache statistics
|
|
48
|
-
*/
|
|
49
|
-
getStats?(): Promise<CacheStats>;
|
|
50
|
-
/**
|
|
51
|
-
* Check cache health
|
|
52
|
-
*/
|
|
53
|
-
isAlive(): Promise<HealthCheckResponse>;
|
|
54
|
-
/**
|
|
55
|
-
* Close/disconnect cache connection
|
|
56
|
-
*/
|
|
57
|
-
close(): Promise<void>;
|
|
58
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import type { SessionData } from '../../types';
|
|
2
|
-
/**
|
|
3
|
-
* Session store interface
|
|
4
|
-
*/
|
|
5
|
-
export interface ISession {
|
|
6
|
-
/**
|
|
7
|
-
* Get session data
|
|
8
|
-
*/
|
|
9
|
-
get(sessionId: string): Promise<SessionData | null>;
|
|
10
|
-
/**
|
|
11
|
-
* Set session data
|
|
12
|
-
*/
|
|
13
|
-
set(sessionId: string, data: SessionData, ttl?: number): Promise<void>;
|
|
14
|
-
/**
|
|
15
|
-
* Delete session
|
|
16
|
-
*/
|
|
17
|
-
delete(sessionId: string): Promise<boolean>;
|
|
18
|
-
/**
|
|
19
|
-
* Check if session exists
|
|
20
|
-
*/
|
|
21
|
-
exists(sessionId: string): Promise<boolean>;
|
|
22
|
-
/**
|
|
23
|
-
* Clear all sessions
|
|
24
|
-
*/
|
|
25
|
-
clear(): Promise<void>;
|
|
26
|
-
/**
|
|
27
|
-
* Update/merge session data
|
|
28
|
-
*/
|
|
29
|
-
update(sessionId: string, data: Partial<SessionData>): Promise<void>;
|
|
30
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { AppError } from '@naman_deep_singh/errors';
|
|
2
|
-
import type { CacheErrorCode } from './cacheErrorCodes';
|
|
3
|
-
export declare class CacheError extends AppError {
|
|
4
|
-
readonly adapter?: string;
|
|
5
|
-
readonly operation?: string;
|
|
6
|
-
constructor(code: CacheErrorCode, options?: {
|
|
7
|
-
adapter?: string;
|
|
8
|
-
operation?: string;
|
|
9
|
-
details?: unknown;
|
|
10
|
-
cause?: Error;
|
|
11
|
-
});
|
|
12
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
export declare const CACHE_ERROR_CODES: {
|
|
2
|
-
readonly CACHE_ERROR: "Temporary caching issue, please retry";
|
|
3
|
-
readonly CACHE_CONNECTION_FAILED: "Failed to connect to the cache server";
|
|
4
|
-
readonly CACHE_UNSUPPORTED_ADAPTER: "The specified cache adapter is not supported";
|
|
5
|
-
readonly CACHE_INVALID_CONFIG: "The provided cache configuration is invalid";
|
|
6
|
-
readonly CACHE_KEY_NOT_FOUND: "The requested cache key was not found";
|
|
7
|
-
readonly CACHE_OPERATION_TIMEOUT: "The cache operation timed out";
|
|
8
|
-
readonly CACHE_SERIALIZE_ERROR: "Failed to serialize cached data";
|
|
9
|
-
readonly CACHE_DESERIALIZE_ERROR: "Failed to deserialize cached data";
|
|
10
|
-
readonly SESSION_CREATE_ERROR: "Failed to create a new session";
|
|
11
|
-
readonly SESSION_GET_ERROR: "Failed to get session data";
|
|
12
|
-
readonly SESSION_UPDATE_ERROR: "Failed to update session data";
|
|
13
|
-
readonly SESSION_DELETE_ERROR: "Failed to delete session data";
|
|
14
|
-
readonly SESSION_EXISTS_ERROR: "Failed to check session existence";
|
|
15
|
-
readonly SESSION_CLEAR_ERROR: "Failed to clear sessions";
|
|
16
|
-
readonly SESSION_GET_MULTIPLE_ERROR: "Failed to get multiple sessions";
|
|
17
|
-
readonly SESSION_DELETE_MULTIPLE_ERROR: "Failed to delete multiple sessions";
|
|
18
|
-
readonly SESSION_EXTEND_ERROR: "Failed to extend session expiry";
|
|
19
|
-
readonly SESSION_GET_EXTEND_ERROR: "Failed to get and extend session data";
|
|
20
|
-
readonly SESSION_NOT_FOUND: "Session not found";
|
|
21
|
-
};
|
|
22
|
-
export type CacheErrorCode = (typeof CACHE_ERROR_CODES)[keyof typeof CACHE_ERROR_CODES];
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { CacheError } from './CacheError';
|
package/dist/cjs/index.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export type { CacheConfig, RedisCacheConfig, MemcacheCacheConfig, MemoryCacheConfig, SessionData, SessionOptions, CacheStats, HealthCheckResponse, BatchResult, CacheEntry, } from './types';
|
|
2
|
-
export { CacheError } from './errors';
|
|
3
|
-
export type { ICache, ISession } from './core/interfaces';
|
|
4
|
-
export { BaseCache } from './core/BaseCache';
|
|
5
|
-
export { RedisCache } from './adapters/redis';
|
|
6
|
-
export { MemcacheCache } from './adapters/memcache';
|
|
7
|
-
export { MemoryCache } from './adapters/memory';
|
|
8
|
-
export { CacheFactory } from './core/factory';
|
|
9
|
-
export { SessionStore } from './session';
|
|
10
|
-
export { cacheSessionMiddleware, cacheHealthCheckMiddleware, cacheResponseMiddleware, } from './middleware/express';
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import type { NextFunction, Request, Response } from 'express';
|
|
2
|
-
import type { ICache } from '../../core/interfaces';
|
|
3
|
-
import type { SessionStore } from '../../session/SessionStore';
|
|
4
|
-
/**
|
|
5
|
-
* Express middleware for session management using cache
|
|
6
|
-
*/
|
|
7
|
-
export declare function cacheSessionMiddleware(sessionStore: SessionStore, options?: {
|
|
8
|
-
sessionIdHeader?: string;
|
|
9
|
-
sessionDataKey?: string;
|
|
10
|
-
}): (req: Request, _res: Response, next: NextFunction) => Promise<void>;
|
|
11
|
-
/**
|
|
12
|
-
* Express middleware for cache health check
|
|
13
|
-
*/
|
|
14
|
-
export declare function cacheHealthCheckMiddleware(cache: ICache, endpoint?: string): (req: Request, res: Response, next: NextFunction) => void;
|
|
15
|
-
/**
|
|
16
|
-
* Express middleware for cache request/response caching
|
|
17
|
-
*/
|
|
18
|
-
export declare function cacheResponseMiddleware(cache: ICache<string>, options?: {
|
|
19
|
-
ttl?: number;
|
|
20
|
-
keyPrefix?: string;
|
|
21
|
-
excludeStatusCodes?: number[];
|
|
22
|
-
}): (req: Request, res: Response, next: NextFunction) => void;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { cacheSessionMiddleware, cacheHealthCheckMiddleware, cacheResponseMiddleware, } from './cacheMiddleware';
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import type { ICache } from '../core/interfaces';
|
|
2
|
-
import type { SessionData, SessionOptions } from '../types';
|
|
3
|
-
/**
|
|
4
|
-
* Session store wrapper around cache adapters
|
|
5
|
-
* Provides session management functionality
|
|
6
|
-
*/
|
|
7
|
-
export declare class SessionStore {
|
|
8
|
-
private cache;
|
|
9
|
-
private options;
|
|
10
|
-
constructor(cache: ICache<SessionData>, options?: SessionOptions);
|
|
11
|
-
/**
|
|
12
|
-
* Create a new session
|
|
13
|
-
*/
|
|
14
|
-
create(sessionId: string, data: SessionData, ttl?: number): Promise<void>;
|
|
15
|
-
/**
|
|
16
|
-
* Get session data
|
|
17
|
-
*/
|
|
18
|
-
get(sessionId: string): Promise<SessionData | null>;
|
|
19
|
-
/**
|
|
20
|
-
* Update/merge session data
|
|
21
|
-
*/
|
|
22
|
-
update(sessionId: string, data: Partial<SessionData>): Promise<void>;
|
|
23
|
-
/**
|
|
24
|
-
* Delete session
|
|
25
|
-
*/
|
|
26
|
-
delete(sessionId: string): Promise<boolean>;
|
|
27
|
-
/**
|
|
28
|
-
* Check if session exists
|
|
29
|
-
*/
|
|
30
|
-
exists(sessionId: string): Promise<boolean>;
|
|
31
|
-
/**
|
|
32
|
-
* Clear all sessions
|
|
33
|
-
*/
|
|
34
|
-
clear(): Promise<void>;
|
|
35
|
-
/**
|
|
36
|
-
* Get all session keys (limited use - may be slow with large datasets)
|
|
37
|
-
*/
|
|
38
|
-
getMultiple(sessionIds: string[]): Promise<Record<string, SessionData | null>>;
|
|
39
|
-
/**
|
|
40
|
-
* Delete multiple sessions
|
|
41
|
-
*/
|
|
42
|
-
deleteMultiple(sessionIds: string[]): Promise<number>;
|
|
43
|
-
/**
|
|
44
|
-
* Extend session expiry
|
|
45
|
-
*/
|
|
46
|
-
extend(sessionId: string, ttl?: number): Promise<void>;
|
|
47
|
-
/**
|
|
48
|
-
* Get session data and extend expiry in one operation
|
|
49
|
-
*/
|
|
50
|
-
getAndExtend(sessionId: string, ttl?: number): Promise<SessionData | null>;
|
|
51
|
-
/**
|
|
52
|
-
* Optional close hook for graceful shutdowns.
|
|
53
|
-
* Present to allow callers to call `close()` during shutdown without
|
|
54
|
-
* requiring every store implementation to provide one.
|
|
55
|
-
*/
|
|
56
|
-
close(): Promise<void>;
|
|
57
|
-
}
|
package/dist/cjs/types.d.ts
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Cache configuration options
|
|
3
|
-
*/
|
|
4
|
-
export interface CacheConfig {
|
|
5
|
-
adapter: 'redis' | 'memcache' | 'memory';
|
|
6
|
-
namespace?: string;
|
|
7
|
-
ttl?: number;
|
|
8
|
-
fallback?: boolean;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Redis-cluster configuration
|
|
12
|
-
*/
|
|
13
|
-
export interface RedisClusterConfig {
|
|
14
|
-
nodes: Array<{
|
|
15
|
-
host: string;
|
|
16
|
-
port: number;
|
|
17
|
-
}>;
|
|
18
|
-
options?: {
|
|
19
|
-
enableReadyCheck?: boolean;
|
|
20
|
-
maxRedirections?: number;
|
|
21
|
-
retryDelayOnFailover?: number;
|
|
22
|
-
retryDelayOnClusterDown?: number;
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Redis-specific configuration
|
|
27
|
-
*/
|
|
28
|
-
export interface RedisCacheConfig extends CacheConfig {
|
|
29
|
-
adapter: 'redis';
|
|
30
|
-
host?: string;
|
|
31
|
-
port?: number;
|
|
32
|
-
cluster?: RedisClusterConfig | Array<{
|
|
33
|
-
host: string;
|
|
34
|
-
port: number;
|
|
35
|
-
}>;
|
|
36
|
-
username?: string;
|
|
37
|
-
password?: string;
|
|
38
|
-
db?: number;
|
|
39
|
-
tls?: boolean;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Memcache-specific configuration
|
|
43
|
-
*/
|
|
44
|
-
export interface MemcacheCacheConfig extends CacheConfig {
|
|
45
|
-
adapter: 'memcache';
|
|
46
|
-
servers: string | string[];
|
|
47
|
-
username?: string;
|
|
48
|
-
password?: string;
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Memory cache configuration
|
|
52
|
-
*/
|
|
53
|
-
export interface MemoryCacheConfig extends CacheConfig {
|
|
54
|
-
adapter: 'memory';
|
|
55
|
-
maxSize?: number;
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Session data structure
|
|
59
|
-
*/
|
|
60
|
-
export interface SessionData {
|
|
61
|
-
[key: string]: unknown;
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Session store options
|
|
65
|
-
*/
|
|
66
|
-
export interface SessionOptions {
|
|
67
|
-
ttl?: number;
|
|
68
|
-
serialize?: (data: SessionData) => string;
|
|
69
|
-
deserialize?: (data: string) => SessionData;
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Cache statistics
|
|
73
|
-
*/
|
|
74
|
-
export interface CacheStats {
|
|
75
|
-
hits: number;
|
|
76
|
-
misses: number;
|
|
77
|
-
sets: number;
|
|
78
|
-
deletes: number;
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* Health check response
|
|
82
|
-
*/
|
|
83
|
-
export interface HealthCheckResponse {
|
|
84
|
-
isAlive: boolean;
|
|
85
|
-
adapter: string;
|
|
86
|
-
timestamp: Date;
|
|
87
|
-
error?: string;
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Batch operation result
|
|
91
|
-
*/
|
|
92
|
-
export interface BatchResult<T> {
|
|
93
|
-
[key: string]: T | null;
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* Cache key with optional metadata
|
|
97
|
-
*/
|
|
98
|
-
export interface CacheEntry<T = unknown> {
|
|
99
|
-
value: T;
|
|
100
|
-
expiresAt?: number;
|
|
101
|
-
createdAt: number;
|
|
102
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { BaseCache } from '../../core/BaseCache';
|
|
2
|
-
import type { HealthCheckResponse, MemcacheCacheConfig } from '../../types';
|
|
3
|
-
export declare class MemcacheCache<T = unknown> extends BaseCache<T> {
|
|
4
|
-
private memcacheConfig;
|
|
5
|
-
private client;
|
|
6
|
-
private isConnected;
|
|
7
|
-
constructor(memcacheConfig: MemcacheCacheConfig);
|
|
8
|
-
connect(): Promise<void>;
|
|
9
|
-
private ensureConnected;
|
|
10
|
-
private ping;
|
|
11
|
-
exists(key: string): Promise<boolean>;
|
|
12
|
-
get(key: string): Promise<T | null>;
|
|
13
|
-
set(key: string, value: T, ttl?: number): Promise<void>;
|
|
14
|
-
delete(key: string): Promise<boolean>;
|
|
15
|
-
clear(): Promise<void>;
|
|
16
|
-
isAlive(): Promise<HealthCheckResponse>;
|
|
17
|
-
close(): Promise<void>;
|
|
18
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { MemcacheCache } from './MemcacheCache';
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { BaseCache } from '../../core/BaseCache';
|
|
2
|
-
import type { HealthCheckResponse, MemoryCacheConfig } from '../../types';
|
|
3
|
-
/**
|
|
4
|
-
* In-memory cache adapter for development and testing
|
|
5
|
-
*/
|
|
6
|
-
export declare class MemoryCache<T = unknown> extends BaseCache<T> {
|
|
7
|
-
private memoryCacheConfig;
|
|
8
|
-
private store;
|
|
9
|
-
private cleanupInterval;
|
|
10
|
-
constructor(memoryCacheConfig: MemoryCacheConfig);
|
|
11
|
-
/**
|
|
12
|
-
* Start periodic cleanup of expired items
|
|
13
|
-
*/
|
|
14
|
-
private startCleanup;
|
|
15
|
-
/**
|
|
16
|
-
* Get a value from memory
|
|
17
|
-
*/
|
|
18
|
-
get(key: string): Promise<T | null>;
|
|
19
|
-
/**
|
|
20
|
-
* Set a value in memory
|
|
21
|
-
*/
|
|
22
|
-
set(key: string, value: T, ttl?: number): Promise<void>;
|
|
23
|
-
/**
|
|
24
|
-
* Delete a key from memory
|
|
25
|
-
*/
|
|
26
|
-
delete(key: string): Promise<boolean>;
|
|
27
|
-
/**
|
|
28
|
-
* Check if key exists
|
|
29
|
-
*/
|
|
30
|
-
exists(key: string): Promise<boolean>;
|
|
31
|
-
/**
|
|
32
|
-
* Clear all keys with current namespace
|
|
33
|
-
*/
|
|
34
|
-
clear(): Promise<void>;
|
|
35
|
-
/**
|
|
36
|
-
* Get multiple values at once
|
|
37
|
-
*/
|
|
38
|
-
getMultiple(keys: string[]): Promise<Record<string, T | null>>;
|
|
39
|
-
/**
|
|
40
|
-
* Set multiple values at once
|
|
41
|
-
*/
|
|
42
|
-
setMultiple(data: Record<string, T>, ttl?: number): Promise<void>;
|
|
43
|
-
/**
|
|
44
|
-
* Delete multiple keys at once
|
|
45
|
-
*/
|
|
46
|
-
deleteMultiple(keys: string[]): Promise<number>;
|
|
47
|
-
/**
|
|
48
|
-
* Increment a numeric value
|
|
49
|
-
*/
|
|
50
|
-
increment(key: string, amount?: number): Promise<number>;
|
|
51
|
-
/**
|
|
52
|
-
* Decrement a numeric value
|
|
53
|
-
*/
|
|
54
|
-
decrement(key: string, amount?: number): Promise<number>;
|
|
55
|
-
/**
|
|
56
|
-
* Check if memory cache is alive
|
|
57
|
-
*/
|
|
58
|
-
isAlive(): Promise<HealthCheckResponse>;
|
|
59
|
-
/**
|
|
60
|
-
* Close memory cache
|
|
61
|
-
*/
|
|
62
|
-
close(): Promise<void>;
|
|
63
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { MemoryCache } from './MemoryCache';
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { BaseCache } from '../../core/BaseCache';
|
|
2
|
-
import type { HealthCheckResponse, RedisCacheConfig } from '../../types';
|
|
3
|
-
/**
|
|
4
|
-
* Redis cache adapter
|
|
5
|
-
*/
|
|
6
|
-
export declare class RedisCache<T = unknown> extends BaseCache<T> {
|
|
7
|
-
private redisConfig;
|
|
8
|
-
private client;
|
|
9
|
-
private isConnected;
|
|
10
|
-
constructor(redisConfig: RedisCacheConfig);
|
|
11
|
-
/**
|
|
12
|
-
* Connect to Redis
|
|
13
|
-
*/
|
|
14
|
-
connect(): Promise<void>;
|
|
15
|
-
/**
|
|
16
|
-
* Ensure client is connected
|
|
17
|
-
*/
|
|
18
|
-
private ensureConnected;
|
|
19
|
-
/**
|
|
20
|
-
* Get a value from Redis
|
|
21
|
-
*/
|
|
22
|
-
get(key: string): Promise<T | null>;
|
|
23
|
-
/**
|
|
24
|
-
* Set a value in Redis
|
|
25
|
-
*/
|
|
26
|
-
set(key: string, value: T, ttl?: number): Promise<void>;
|
|
27
|
-
/**
|
|
28
|
-
* Delete a key from Redis
|
|
29
|
-
*/
|
|
30
|
-
delete(key: string): Promise<boolean>;
|
|
31
|
-
/**
|
|
32
|
-
* Check if key exists
|
|
33
|
-
*/
|
|
34
|
-
exists(key: string): Promise<boolean>;
|
|
35
|
-
/**
|
|
36
|
-
* Clear all keys with current namespace
|
|
37
|
-
*/
|
|
38
|
-
clear(): Promise<void>;
|
|
39
|
-
/**
|
|
40
|
-
* Get multiple values at once
|
|
41
|
-
*/
|
|
42
|
-
getMultiple(keys: string[]): Promise<Record<string, T | null>>;
|
|
43
|
-
/**
|
|
44
|
-
* Set multiple values at once
|
|
45
|
-
*/
|
|
46
|
-
setMultiple(data: Record<string, T>, ttl?: number): Promise<void>;
|
|
47
|
-
/**
|
|
48
|
-
* Delete multiple keys at once
|
|
49
|
-
*/
|
|
50
|
-
deleteMultiple(keys: string[]): Promise<number>;
|
|
51
|
-
/**
|
|
52
|
-
* Increment a numeric value
|
|
53
|
-
*/
|
|
54
|
-
increment(key: string, amount?: number): Promise<number>;
|
|
55
|
-
/**
|
|
56
|
-
* Decrement a numeric value
|
|
57
|
-
*/
|
|
58
|
-
decrement(key: string, amount?: number): Promise<number>;
|
|
59
|
-
/**
|
|
60
|
-
* Check if Redis is alive
|
|
61
|
-
*/
|
|
62
|
-
isAlive(): Promise<HealthCheckResponse>;
|
|
63
|
-
/**
|
|
64
|
-
* Close Redis connection
|
|
65
|
-
*/
|
|
66
|
-
close(): Promise<void>;
|
|
67
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { RedisCache } from './RedisCache';
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import type { BatchResult, CacheConfig, CacheStats, HealthCheckResponse } from '../types';
|
|
2
|
-
import type { ICache } from './interfaces';
|
|
3
|
-
/**
|
|
4
|
-
* Abstract base class for all cache adapters
|
|
5
|
-
*/
|
|
6
|
-
export declare abstract class BaseCache<T = unknown> implements ICache<T> {
|
|
7
|
-
protected config: CacheConfig;
|
|
8
|
-
protected readonly namespace: string;
|
|
9
|
-
protected readonly ttl: number;
|
|
10
|
-
protected stats: CacheStats;
|
|
11
|
-
constructor(config: CacheConfig);
|
|
12
|
-
/**
|
|
13
|
-
* Build full key with namespace prefix
|
|
14
|
-
*/
|
|
15
|
-
protected buildKey(key: string): string;
|
|
16
|
-
/**
|
|
17
|
-
* Deserialize string to object
|
|
18
|
-
*/
|
|
19
|
-
protected deserialize(data: string): T;
|
|
20
|
-
/**
|
|
21
|
-
* Serialize object to string
|
|
22
|
-
*/
|
|
23
|
-
protected serialize(value: T): string;
|
|
24
|
-
/**
|
|
25
|
-
* Track cache hit
|
|
26
|
-
*/
|
|
27
|
-
protected recordHit(): void;
|
|
28
|
-
/**
|
|
29
|
-
* Track cache miss
|
|
30
|
-
*/
|
|
31
|
-
protected recordMiss(): void;
|
|
32
|
-
/**
|
|
33
|
-
* Track cache set
|
|
34
|
-
*/
|
|
35
|
-
protected recordSet(): void;
|
|
36
|
-
/**
|
|
37
|
-
* Track cache delete
|
|
38
|
-
*/
|
|
39
|
-
protected recordDelete(): void;
|
|
40
|
-
/**
|
|
41
|
-
* Reset statistics
|
|
42
|
-
*/
|
|
43
|
-
protected resetStats(): void;
|
|
44
|
-
/**
|
|
45
|
-
* Get cache statistics
|
|
46
|
-
*/
|
|
47
|
-
getStats(): Promise<CacheStats>;
|
|
48
|
-
/**
|
|
49
|
-
* Abstract methods - must be implemented by subclasses
|
|
50
|
-
*/
|
|
51
|
-
abstract get(key: string): Promise<T | null>;
|
|
52
|
-
abstract set(key: string, value: T, ttl?: number): Promise<void>;
|
|
53
|
-
abstract delete(key: string): Promise<boolean>;
|
|
54
|
-
abstract exists(key: string): Promise<boolean>;
|
|
55
|
-
abstract clear(): Promise<void>;
|
|
56
|
-
abstract isAlive(): Promise<HealthCheckResponse>;
|
|
57
|
-
abstract close(): Promise<void>;
|
|
58
|
-
/**
|
|
59
|
-
* Default implementation for getMultiple
|
|
60
|
-
*/
|
|
61
|
-
getMultiple(keys: string[]): Promise<BatchResult<T>>;
|
|
62
|
-
/**
|
|
63
|
-
* Default implementation for setMultiple
|
|
64
|
-
*/
|
|
65
|
-
setMultiple(data: Record<string, T>, ttl?: number): Promise<void>;
|
|
66
|
-
/**
|
|
67
|
-
* Default implementation for deleteMultiple
|
|
68
|
-
*/
|
|
69
|
-
deleteMultiple(keys: string[]): Promise<number>;
|
|
70
|
-
/**
|
|
71
|
-
* Default implementation for increment
|
|
72
|
-
*/
|
|
73
|
-
increment(key: string, amount?: number): Promise<number>;
|
|
74
|
-
/**
|
|
75
|
-
* Default implementation for decrement
|
|
76
|
-
*/
|
|
77
|
-
decrement(key: string, amount?: number): Promise<number>;
|
|
78
|
-
}
|