cacheable 2.0.2 → 2.1.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/dist/index.d.cts CHANGED
@@ -2,11 +2,75 @@ import { WrapFunctionOptions, GetOrSetKey, GetOrSetFunctionOptions } from '@cach
2
2
  export { GetOrSetFunctionOptions, GetOrSetKey, GetOrSetOptions, WrapOptions, WrapSyncOptions, getOrSet, wrap, wrapSync } from '@cacheable/memoize';
3
3
  import { Stats, CacheableItem, HashAlgorithm } from '@cacheable/utils';
4
4
  export { CacheableItem, Stats as CacheableStats, HashAlgorithm, calculateTtlFromExpiration, getCascadingTtl, hash, shorthandToMilliseconds, shorthandToTime } from '@cacheable/utils';
5
- import { Hookified } from 'hookified';
5
+ import { Hookified, HookifiedOptions } from 'hookified';
6
6
  import { Keyv, KeyvStoreAdapter, StoredDataRaw } from 'keyv';
7
7
  export { Keyv, KeyvHooks, KeyvOptions, KeyvStoreAdapter } from 'keyv';
8
+ import { Qified, MessageProvider } from 'qified';
8
9
  export { CacheableMemory, CacheableMemoryOptions, KeyvCacheableMemory, KeyvCacheableMemoryOptions, createKeyv } from '@cacheable/memory';
9
10
 
11
+ /**
12
+ * Events emitted by CacheableSync
13
+ */
14
+ declare enum CacheableSyncEvents {
15
+ ERROR = "error",
16
+ SET = "cache:set",
17
+ DELETE = "cache:delete"
18
+ }
19
+ /**
20
+ * Configuration options for CacheableSync
21
+ */
22
+ type CacheableSyncOptions = {
23
+ /**
24
+ * Qified instance or message provider(s) for synchronization
25
+ */
26
+ qified: Qified | MessageProvider | MessageProvider[];
27
+ } & HookifiedOptions;
28
+ type CacheableSyncItem = {
29
+ cacheId: string;
30
+ key: string;
31
+ value?: unknown;
32
+ ttl?: number;
33
+ };
34
+ /**
35
+ * CacheableSync provides synchronization capabilities for cacheable items
36
+ * using message providers from Qified
37
+ */
38
+ declare class CacheableSync extends Hookified {
39
+ private _qified;
40
+ /**
41
+ * Creates an instance of CacheableSync
42
+ * @param options - Configuration options for CacheableSync
43
+ */
44
+ constructor(options: CacheableSyncOptions);
45
+ /**
46
+ * Gets the Qified instance used for synchronization
47
+ * @returns The Qified instance
48
+ */
49
+ get qified(): Qified;
50
+ /**
51
+ * Sets the Qified instance used for synchronization
52
+ * @param value - Either an existing Qified instance or MessageProvider(s)
53
+ */
54
+ set qified(value: Qified | MessageProvider | MessageProvider[]);
55
+ /**
56
+ * Publishes a cache event to all the cache instances
57
+ * @param data - The cache item data containing cacheId, key, value, and optional ttl
58
+ */
59
+ publish(event: CacheableSyncEvents, data: CacheableSyncItem): Promise<void>;
60
+ /**
61
+ * Subscribes to sync events and updates the provided storage
62
+ * @param storage - The Keyv storage instance to update
63
+ * @param cacheId - The cache ID to identify this instance
64
+ */
65
+ subscribe(storage: Keyv, cacheId: string): void;
66
+ /**
67
+ * Creates or returns a Qified instance from the provided value
68
+ * @param value - Either an existing Qified instance or MessageProvider(s)
69
+ * @returns A Qified instance configured with the provided message provider(s)
70
+ */
71
+ createQified(value: Qified | MessageProvider | MessageProvider[]): Qified;
72
+ }
73
+
10
74
  type CacheableOptions = {
11
75
  /**
12
76
  * The primary store for the cacheable instance
@@ -40,6 +104,10 @@ type CacheableOptions = {
40
104
  * If it is not set then it will be a random string that is generated
41
105
  */
42
106
  cacheId?: string;
107
+ /**
108
+ * The sync instance for the cacheable instance to enable synchronization across cache instances
109
+ */
110
+ sync?: CacheableSync | CacheableSyncOptions;
43
111
  };
44
112
  type GetOptions = {
45
113
  /**
@@ -74,6 +142,7 @@ declare class Cacheable extends Hookified {
74
142
  private readonly _stats;
75
143
  private _namespace?;
76
144
  private _cacheId;
145
+ private _sync?;
77
146
  /**
78
147
  * Creates a new cacheable instance
79
148
  * @param {CacheableOptions} [options] The options for the cacheable instance
@@ -183,6 +252,16 @@ declare class Cacheable extends Hookified {
183
252
  * @param {string} cacheId The cacheId for the cacheable instance
184
253
  */
185
254
  set cacheId(cacheId: string);
255
+ /**
256
+ * Gets the sync instance for the cacheable instance
257
+ * @returns {CacheableSync | undefined} The sync instance for the cacheable instance
258
+ */
259
+ get sync(): CacheableSync | undefined;
260
+ /**
261
+ * Sets the sync instance for the cacheable instance
262
+ * @param {CacheableSync | undefined} sync The sync instance for the cacheable instance
263
+ */
264
+ set sync(sync: CacheableSync | undefined);
186
265
  /**
187
266
  * Sets the primary store for the cacheable instance
188
267
  * @param {Keyv | KeyvStoreAdapter} primary The primary store for the cacheable instance
@@ -195,7 +274,6 @@ declare class Cacheable extends Hookified {
195
274
  * @returns {void}
196
275
  */
197
276
  setSecondary(secondary: Keyv | KeyvStoreAdapter): void;
198
- isKeyvInstance(keyv: any): boolean;
199
277
  getNameSpace(): string | undefined;
200
278
  /**
201
279
  * Retrieves an entry from the cache.
@@ -376,4 +454,4 @@ declare class Cacheable extends Hookified {
376
454
  private setTtl;
377
455
  }
378
456
 
379
- export { Cacheable, CacheableEvents, CacheableHooks, type CacheableOptions };
457
+ export { Cacheable, CacheableEvents, CacheableHooks, type CacheableOptions, CacheableSync, CacheableSyncEvents, type CacheableSyncItem, type CacheableSyncOptions };
package/dist/index.d.ts CHANGED
@@ -2,11 +2,75 @@ import { WrapFunctionOptions, GetOrSetKey, GetOrSetFunctionOptions } from '@cach
2
2
  export { GetOrSetFunctionOptions, GetOrSetKey, GetOrSetOptions, WrapOptions, WrapSyncOptions, getOrSet, wrap, wrapSync } from '@cacheable/memoize';
3
3
  import { Stats, CacheableItem, HashAlgorithm } from '@cacheable/utils';
4
4
  export { CacheableItem, Stats as CacheableStats, HashAlgorithm, calculateTtlFromExpiration, getCascadingTtl, hash, shorthandToMilliseconds, shorthandToTime } from '@cacheable/utils';
5
- import { Hookified } from 'hookified';
5
+ import { Hookified, HookifiedOptions } from 'hookified';
6
6
  import { Keyv, KeyvStoreAdapter, StoredDataRaw } from 'keyv';
7
7
  export { Keyv, KeyvHooks, KeyvOptions, KeyvStoreAdapter } from 'keyv';
8
+ import { Qified, MessageProvider } from 'qified';
8
9
  export { CacheableMemory, CacheableMemoryOptions, KeyvCacheableMemory, KeyvCacheableMemoryOptions, createKeyv } from '@cacheable/memory';
9
10
 
11
+ /**
12
+ * Events emitted by CacheableSync
13
+ */
14
+ declare enum CacheableSyncEvents {
15
+ ERROR = "error",
16
+ SET = "cache:set",
17
+ DELETE = "cache:delete"
18
+ }
19
+ /**
20
+ * Configuration options for CacheableSync
21
+ */
22
+ type CacheableSyncOptions = {
23
+ /**
24
+ * Qified instance or message provider(s) for synchronization
25
+ */
26
+ qified: Qified | MessageProvider | MessageProvider[];
27
+ } & HookifiedOptions;
28
+ type CacheableSyncItem = {
29
+ cacheId: string;
30
+ key: string;
31
+ value?: unknown;
32
+ ttl?: number;
33
+ };
34
+ /**
35
+ * CacheableSync provides synchronization capabilities for cacheable items
36
+ * using message providers from Qified
37
+ */
38
+ declare class CacheableSync extends Hookified {
39
+ private _qified;
40
+ /**
41
+ * Creates an instance of CacheableSync
42
+ * @param options - Configuration options for CacheableSync
43
+ */
44
+ constructor(options: CacheableSyncOptions);
45
+ /**
46
+ * Gets the Qified instance used for synchronization
47
+ * @returns The Qified instance
48
+ */
49
+ get qified(): Qified;
50
+ /**
51
+ * Sets the Qified instance used for synchronization
52
+ * @param value - Either an existing Qified instance or MessageProvider(s)
53
+ */
54
+ set qified(value: Qified | MessageProvider | MessageProvider[]);
55
+ /**
56
+ * Publishes a cache event to all the cache instances
57
+ * @param data - The cache item data containing cacheId, key, value, and optional ttl
58
+ */
59
+ publish(event: CacheableSyncEvents, data: CacheableSyncItem): Promise<void>;
60
+ /**
61
+ * Subscribes to sync events and updates the provided storage
62
+ * @param storage - The Keyv storage instance to update
63
+ * @param cacheId - The cache ID to identify this instance
64
+ */
65
+ subscribe(storage: Keyv, cacheId: string): void;
66
+ /**
67
+ * Creates or returns a Qified instance from the provided value
68
+ * @param value - Either an existing Qified instance or MessageProvider(s)
69
+ * @returns A Qified instance configured with the provided message provider(s)
70
+ */
71
+ createQified(value: Qified | MessageProvider | MessageProvider[]): Qified;
72
+ }
73
+
10
74
  type CacheableOptions = {
11
75
  /**
12
76
  * The primary store for the cacheable instance
@@ -40,6 +104,10 @@ type CacheableOptions = {
40
104
  * If it is not set then it will be a random string that is generated
41
105
  */
42
106
  cacheId?: string;
107
+ /**
108
+ * The sync instance for the cacheable instance to enable synchronization across cache instances
109
+ */
110
+ sync?: CacheableSync | CacheableSyncOptions;
43
111
  };
44
112
  type GetOptions = {
45
113
  /**
@@ -74,6 +142,7 @@ declare class Cacheable extends Hookified {
74
142
  private readonly _stats;
75
143
  private _namespace?;
76
144
  private _cacheId;
145
+ private _sync?;
77
146
  /**
78
147
  * Creates a new cacheable instance
79
148
  * @param {CacheableOptions} [options] The options for the cacheable instance
@@ -183,6 +252,16 @@ declare class Cacheable extends Hookified {
183
252
  * @param {string} cacheId The cacheId for the cacheable instance
184
253
  */
185
254
  set cacheId(cacheId: string);
255
+ /**
256
+ * Gets the sync instance for the cacheable instance
257
+ * @returns {CacheableSync | undefined} The sync instance for the cacheable instance
258
+ */
259
+ get sync(): CacheableSync | undefined;
260
+ /**
261
+ * Sets the sync instance for the cacheable instance
262
+ * @param {CacheableSync | undefined} sync The sync instance for the cacheable instance
263
+ */
264
+ set sync(sync: CacheableSync | undefined);
186
265
  /**
187
266
  * Sets the primary store for the cacheable instance
188
267
  * @param {Keyv | KeyvStoreAdapter} primary The primary store for the cacheable instance
@@ -195,7 +274,6 @@ declare class Cacheable extends Hookified {
195
274
  * @returns {void}
196
275
  */
197
276
  setSecondary(secondary: Keyv | KeyvStoreAdapter): void;
198
- isKeyvInstance(keyv: any): boolean;
199
277
  getNameSpace(): string | undefined;
200
278
  /**
201
279
  * Retrieves an entry from the cache.
@@ -376,4 +454,4 @@ declare class Cacheable extends Hookified {
376
454
  private setTtl;
377
455
  }
378
456
 
379
- export { Cacheable, CacheableEvents, CacheableHooks, type CacheableOptions };
457
+ export { Cacheable, CacheableEvents, CacheableHooks, type CacheableOptions, CacheableSync, CacheableSyncEvents, type CacheableSyncItem, type CacheableSyncOptions };