@tekir/cache 0.1.0 → 0.1.1
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/dist/cache.d.ts +3 -3
- package/dist/index.d.ts +1 -1
- package/dist/types.d.ts +24 -0
- package/package.json +2 -2
- package/src/cache.ts +3 -3
- package/src/index.ts +1 -1
- package/src/types.ts +27 -1
package/dist/cache.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { CacheManagerOptions, CacheStore } from './types';
|
|
2
2
|
/**
|
|
3
3
|
* Multi-store cache manager that delegates to configured {@link CacheStore}
|
|
4
4
|
* implementations. Supports named stores, a default TTL, and convenience
|
|
@@ -20,7 +20,7 @@ export declare class Cache {
|
|
|
20
20
|
*
|
|
21
21
|
* @param config - Cache configuration including stores, default store name, and TTL.
|
|
22
22
|
*/
|
|
23
|
-
constructor(config?:
|
|
23
|
+
constructor(config?: CacheManagerOptions);
|
|
24
24
|
/**
|
|
25
25
|
* Retrieve a specific named store, or the default store if no name is given.
|
|
26
26
|
*
|
|
@@ -106,4 +106,4 @@ export declare class Cache {
|
|
|
106
106
|
* const cache = createCache({ ttl: 120 })
|
|
107
107
|
* ```
|
|
108
108
|
*/
|
|
109
|
-
export declare function createCache(config?:
|
|
109
|
+
export declare function createCache(config?: CacheManagerOptions): Cache;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type { CacheStore, CacheConfig } from './types';
|
|
1
|
+
export type { CacheStore, CacheConfig, CacheStoreDriverConfig, CacheManagerOptions } from './types';
|
|
2
2
|
export { MemoryCacheStore } from './stores/memory';
|
|
3
3
|
export { RedisCacheStore } from './stores/redis';
|
|
4
4
|
export { DatabaseCacheStore } from './stores/database';
|
package/dist/types.d.ts
CHANGED
|
@@ -5,7 +5,31 @@ export interface CacheStore {
|
|
|
5
5
|
delete(key: string): Promise<boolean>;
|
|
6
6
|
flush(): Promise<void>;
|
|
7
7
|
}
|
|
8
|
+
/** Driver-based config that the provider expands into a CacheStore instance. */
|
|
9
|
+
export interface CacheStoreDriverConfig {
|
|
10
|
+
driver?: 'memory' | 'redis' | 'database';
|
|
11
|
+
/** Optional key prefix (redis driver). */
|
|
12
|
+
prefix?: string;
|
|
13
|
+
/** Optional table name (database driver). */
|
|
14
|
+
table?: string;
|
|
15
|
+
/** Allow driver-specific extras without losing autocomplete on the known fields. */
|
|
16
|
+
[key: string]: unknown;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* User-facing config shape — what `config/cache.ts` exports. Stores can be
|
|
20
|
+
* either concrete `CacheStore` instances or driver-config objects which the
|
|
21
|
+
* provider expands before instantiating {@link Cache}.
|
|
22
|
+
*/
|
|
8
23
|
export interface CacheConfig {
|
|
24
|
+
default?: string;
|
|
25
|
+
stores?: Record<string, CacheStore | CacheStoreDriverConfig>;
|
|
26
|
+
ttl?: number;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Internal options accepted by the {@link Cache} constructor after the
|
|
30
|
+
* provider has expanded driver configs into concrete stores.
|
|
31
|
+
*/
|
|
32
|
+
export interface CacheManagerOptions {
|
|
9
33
|
default?: string;
|
|
10
34
|
stores?: Record<string, CacheStore>;
|
|
11
35
|
ttl?: number;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tekir/cache",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "In-memory, Redis, and database caching abstraction",
|
|
5
5
|
"author": "dev@tekir.io",
|
|
6
6
|
"license": "MIT",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
}
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@tekir/core": "^0.1.
|
|
42
|
+
"@tekir/core": "^0.1.2"
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|
|
45
45
|
"@tekir/redis": "^0.1.0"
|
package/src/cache.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { CacheManagerOptions, CacheStore } from './types'
|
|
2
2
|
import { MemoryCacheStore } from './stores/memory'
|
|
3
3
|
|
|
4
4
|
|
|
@@ -24,7 +24,7 @@ export class Cache {
|
|
|
24
24
|
*
|
|
25
25
|
* @param config - Cache configuration including stores, default store name, and TTL.
|
|
26
26
|
*/
|
|
27
|
-
constructor(config:
|
|
27
|
+
constructor(config: CacheManagerOptions = {}) {
|
|
28
28
|
this.stores = config.stores || { memory: new MemoryCacheStore() }
|
|
29
29
|
this.defaultStore = config.default || Object.keys(this.stores)[0]
|
|
30
30
|
this.defaultTtl = config.ttl || 3600
|
|
@@ -138,6 +138,6 @@ export class Cache {
|
|
|
138
138
|
* const cache = createCache({ ttl: 120 })
|
|
139
139
|
* ```
|
|
140
140
|
*/
|
|
141
|
-
export function createCache(config?:
|
|
141
|
+
export function createCache(config?: CacheManagerOptions): Cache {
|
|
142
142
|
return new Cache(config)
|
|
143
143
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type { CacheStore, CacheConfig } from './types'
|
|
1
|
+
export type { CacheStore, CacheConfig, CacheStoreDriverConfig, CacheManagerOptions } from './types'
|
|
2
2
|
export { MemoryCacheStore } from './stores/memory'
|
|
3
3
|
export { RedisCacheStore } from './stores/redis'
|
|
4
4
|
export { DatabaseCacheStore } from './stores/database'
|
package/src/types.ts
CHANGED
|
@@ -6,8 +6,34 @@ export interface CacheStore {
|
|
|
6
6
|
flush(): Promise<void>
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
+
/** Driver-based config that the provider expands into a CacheStore instance. */
|
|
10
|
+
export interface CacheStoreDriverConfig {
|
|
11
|
+
driver?: 'memory' | 'redis' | 'database'
|
|
12
|
+
/** Optional key prefix (redis driver). */
|
|
13
|
+
prefix?: string
|
|
14
|
+
/** Optional table name (database driver). */
|
|
15
|
+
table?: string
|
|
16
|
+
/** Allow driver-specific extras without losing autocomplete on the known fields. */
|
|
17
|
+
[key: string]: unknown
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* User-facing config shape — what `config/cache.ts` exports. Stores can be
|
|
22
|
+
* either concrete `CacheStore` instances or driver-config objects which the
|
|
23
|
+
* provider expands before instantiating {@link Cache}.
|
|
24
|
+
*/
|
|
9
25
|
export interface CacheConfig {
|
|
10
26
|
default?: string
|
|
11
|
-
stores?: Record<string, CacheStore>
|
|
27
|
+
stores?: Record<string, CacheStore | CacheStoreDriverConfig>
|
|
12
28
|
ttl?: number // default TTL in seconds
|
|
13
29
|
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Internal options accepted by the {@link Cache} constructor after the
|
|
33
|
+
* provider has expanded driver configs into concrete stores.
|
|
34
|
+
*/
|
|
35
|
+
export interface CacheManagerOptions {
|
|
36
|
+
default?: string
|
|
37
|
+
stores?: Record<string, CacheStore>
|
|
38
|
+
ttl?: number
|
|
39
|
+
}
|