@naman_deep_singh/cache 1.3.2 → 1.4.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 +105 -9
- package/dist/cjs/adapters/memcache/MemcacheCache.d.ts +1 -54
- package/dist/cjs/adapters/memcache/MemcacheCache.js +75 -281
- package/dist/cjs/adapters/memory/MemoryCache.js +76 -22
- package/dist/cjs/adapters/redis/RedisCache.js +84 -26
- package/dist/cjs/core/BaseCache.js +13 -4
- package/dist/cjs/core/factory.js +26 -4
- package/dist/cjs/errors/CacheError.d.ts +10 -7
- package/dist/cjs/errors/CacheError.js +6 -11
- package/dist/cjs/errors/cacheErrorCodes.d.ts +22 -0
- package/dist/cjs/errors/cacheErrorCodes.js +24 -0
- package/dist/cjs/errors/index.js +3 -0
- package/dist/cjs/middleware/express/cacheMiddleware.js +8 -8
- package/dist/cjs/session/SessionStore.js +84 -28
- package/dist/esm/adapters/memcache/MemcacheCache.d.ts +1 -54
- package/dist/esm/adapters/memcache/MemcacheCache.js +75 -281
- package/dist/esm/adapters/memory/MemoryCache.js +76 -22
- package/dist/esm/adapters/redis/RedisCache.js +84 -26
- package/dist/esm/core/BaseCache.js +13 -4
- package/dist/esm/core/factory.js +26 -4
- package/dist/esm/errors/CacheError.d.ts +10 -7
- package/dist/esm/errors/CacheError.js +6 -11
- package/dist/esm/errors/cacheErrorCodes.d.ts +22 -0
- package/dist/esm/errors/cacheErrorCodes.js +21 -0
- package/dist/esm/errors/index.js +3 -0
- package/dist/esm/middleware/express/cacheMiddleware.js +8 -8
- package/dist/esm/session/SessionStore.js +84 -28
- package/dist/types/adapters/memcache/MemcacheCache.d.ts +1 -54
- package/dist/types/errors/CacheError.d.ts +10 -7
- package/dist/types/errors/cacheErrorCodes.d.ts +22 -0
- package/package.json +8 -6
|
@@ -1,71 +1,18 @@
|
|
|
1
1
|
import { BaseCache } from '../../core/BaseCache';
|
|
2
2
|
import type { HealthCheckResponse, MemcacheCacheConfig } from '../../types';
|
|
3
|
-
/**
|
|
4
|
-
* Memcache adapter
|
|
5
|
-
*/
|
|
6
3
|
export declare class MemcacheCache<T = unknown> extends BaseCache<T> {
|
|
7
4
|
private memcacheConfig;
|
|
8
5
|
private client;
|
|
9
6
|
private isConnected;
|
|
10
7
|
constructor(memcacheConfig: MemcacheCacheConfig);
|
|
11
|
-
/**
|
|
12
|
-
* Connect to Memcache
|
|
13
|
-
*/
|
|
14
8
|
connect(): Promise<void>;
|
|
15
|
-
/**
|
|
16
|
-
* Ensure client is connected
|
|
17
|
-
*/
|
|
18
9
|
private ensureConnected;
|
|
19
|
-
/**
|
|
20
|
-
* Ping memcache
|
|
21
|
-
*/
|
|
22
10
|
private ping;
|
|
23
|
-
|
|
24
|
-
* Get a value from Memcache
|
|
25
|
-
*/
|
|
11
|
+
exists(key: string): Promise<boolean>;
|
|
26
12
|
get(key: string): Promise<T | null>;
|
|
27
|
-
/**
|
|
28
|
-
* Set a value in Memcache
|
|
29
|
-
*/
|
|
30
13
|
set(key: string, value: T, ttl?: number): Promise<void>;
|
|
31
|
-
/**
|
|
32
|
-
* Delete a key from Memcache
|
|
33
|
-
*/
|
|
34
14
|
delete(key: string): Promise<boolean>;
|
|
35
|
-
/**
|
|
36
|
-
* Check if key exists
|
|
37
|
-
*/
|
|
38
|
-
exists(key: string): Promise<boolean>;
|
|
39
|
-
/**
|
|
40
|
-
* Clear all keys (Memcache limitation: flushes entire cache)
|
|
41
|
-
*/
|
|
42
15
|
clear(): Promise<void>;
|
|
43
|
-
/**
|
|
44
|
-
* Get multiple values at once
|
|
45
|
-
*/
|
|
46
|
-
getMultiple(keys: string[]): Promise<Record<string, T | null>>;
|
|
47
|
-
/**
|
|
48
|
-
* Set multiple values at once
|
|
49
|
-
*/
|
|
50
|
-
setMultiple(data: Record<string, T>, ttl?: number): Promise<void>;
|
|
51
|
-
/**
|
|
52
|
-
* Delete multiple keys at once
|
|
53
|
-
*/
|
|
54
|
-
deleteMultiple(keys: string[]): Promise<number>;
|
|
55
|
-
/**
|
|
56
|
-
* Increment a numeric value (not natively supported by Memcache in this library)
|
|
57
|
-
*/
|
|
58
|
-
increment(key: string, amount?: number): Promise<number>;
|
|
59
|
-
/**
|
|
60
|
-
* Decrement a numeric value
|
|
61
|
-
*/
|
|
62
|
-
decrement(key: string, amount?: number): Promise<number>;
|
|
63
|
-
/**
|
|
64
|
-
* Check if Memcache is alive
|
|
65
|
-
*/
|
|
66
16
|
isAlive(): Promise<HealthCheckResponse>;
|
|
67
|
-
/**
|
|
68
|
-
* Close Memcache connection
|
|
69
|
-
*/
|
|
70
17
|
close(): Promise<void>;
|
|
71
18
|
}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export declare class CacheError extends Error {
|
|
5
|
-
readonly code: string;
|
|
1
|
+
import { AppError } from '@naman_deep_singh/errors-utils';
|
|
2
|
+
import type { CacheErrorCode } from './cacheErrorCodes';
|
|
3
|
+
export declare class CacheError extends AppError {
|
|
6
4
|
readonly adapter?: string;
|
|
7
|
-
readonly
|
|
8
|
-
constructor(
|
|
5
|
+
readonly operation?: string;
|
|
6
|
+
constructor(code: CacheErrorCode, options?: {
|
|
7
|
+
adapter?: string;
|
|
8
|
+
operation?: string;
|
|
9
|
+
details?: unknown;
|
|
10
|
+
cause?: Error;
|
|
11
|
+
});
|
|
9
12
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
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];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@naman_deep_singh/cache",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "Extensible caching layer supporting Redis, Memcache, and in-memory caches with automatic fallback, namespacing, session management, and Express middleware.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/cjs/index.js",
|
|
@@ -29,16 +29,18 @@
|
|
|
29
29
|
"author": "Naman Deep Singh",
|
|
30
30
|
"license": "ISC",
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@types/memcached": "^2.2.7",
|
|
33
32
|
"@types/express": "^5.0.5",
|
|
33
|
+
"@types/memcached": "^2.2.7",
|
|
34
34
|
"@types/node": "^25.0.1",
|
|
35
35
|
"express": "^5.1.0",
|
|
36
|
-
"
|
|
37
|
-
"
|
|
36
|
+
"rimraf": "^5.0.5",
|
|
37
|
+
"typescript": "^5.9.3"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"
|
|
41
|
-
"
|
|
40
|
+
"@naman_deep_singh/errors-utils": "^1.4.2",
|
|
41
|
+
"@naman_deep_singh/response-utils": "^2.1.4",
|
|
42
|
+
"memcached": "^2.2.2",
|
|
43
|
+
"redis": "^4.6.10"
|
|
42
44
|
},
|
|
43
45
|
"scripts": {
|
|
44
46
|
"build": "pnpm run build:types && tsc -p tsconfig.cjs.json && tsc -p tsconfig.esm.json",
|