@cacheable/memory 1.0.1 → 2.0.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,6 +2,41 @@ import { WrapFunctionOptions } from '@cacheable/memoize';
2
2
  import { HashAlgorithm, CacheableStoreItem, CacheableItem } from '@cacheable/utils';
3
3
  export { CacheableItem, CacheableStoreItem, HashAlgorithm, hash, hashToNumber } from '@cacheable/utils';
4
4
  import { Hookified } from 'hookified';
5
+ import { Keyv, KeyvStoreAdapter, StoredData } from 'keyv';
6
+
7
+ type KeyvCacheableMemoryOptions = CacheableMemoryOptions & {
8
+ namespace?: string;
9
+ };
10
+ declare class KeyvCacheableMemory implements KeyvStoreAdapter {
11
+ opts: CacheableMemoryOptions;
12
+ private readonly _defaultCache;
13
+ private readonly _nCache;
14
+ private _namespace?;
15
+ constructor(options?: KeyvCacheableMemoryOptions);
16
+ get namespace(): string | undefined;
17
+ set namespace(value: string | undefined);
18
+ get store(): CacheableMemory;
19
+ get<Value>(key: string): Promise<StoredData<Value> | undefined>;
20
+ getMany<Value>(keys: string[]): Promise<Array<StoredData<Value | undefined>>>;
21
+ set(key: string, value: any, ttl?: number): Promise<void>;
22
+ setMany(values: Array<{
23
+ key: string;
24
+ value: any;
25
+ ttl?: number;
26
+ }>): Promise<void>;
27
+ delete(key: string): Promise<boolean>;
28
+ deleteMany?(key: string[]): Promise<boolean>;
29
+ clear(): Promise<void>;
30
+ has?(key: string): Promise<boolean>;
31
+ on(event: string, listener: (...arguments_: any[]) => void): this;
32
+ getStore(namespace?: string): CacheableMemory;
33
+ }
34
+ /**
35
+ * Creates a new Keyv instance with a new KeyvCacheableMemory store. This also removes the serialize/deserialize methods from the Keyv instance for optimization.
36
+ * @param options
37
+ * @returns
38
+ */
39
+ declare function createKeyv(options?: KeyvCacheableMemoryOptions): Keyv;
5
40
 
6
41
  type StoreHashAlgorithmFunction = (key: string, storeHashSize: number) => number;
7
42
  /**
@@ -267,4 +302,4 @@ declare class CacheableMemory extends Hookified {
267
302
  private hasExpired;
268
303
  }
269
304
 
270
- export { CacheableMemory, type CacheableMemoryOptions, type SetOptions, type StoreHashAlgorithmFunction, defaultStoreHashSize, maximumMapSize };
305
+ export { CacheableMemory, type CacheableMemoryOptions, KeyvCacheableMemory, type KeyvCacheableMemoryOptions, type SetOptions, type StoreHashAlgorithmFunction, createKeyv, defaultStoreHashSize, maximumMapSize };
package/dist/index.d.ts CHANGED
@@ -2,6 +2,41 @@ import { WrapFunctionOptions } from '@cacheable/memoize';
2
2
  import { HashAlgorithm, CacheableStoreItem, CacheableItem } from '@cacheable/utils';
3
3
  export { CacheableItem, CacheableStoreItem, HashAlgorithm, hash, hashToNumber } from '@cacheable/utils';
4
4
  import { Hookified } from 'hookified';
5
+ import { Keyv, KeyvStoreAdapter, StoredData } from 'keyv';
6
+
7
+ type KeyvCacheableMemoryOptions = CacheableMemoryOptions & {
8
+ namespace?: string;
9
+ };
10
+ declare class KeyvCacheableMemory implements KeyvStoreAdapter {
11
+ opts: CacheableMemoryOptions;
12
+ private readonly _defaultCache;
13
+ private readonly _nCache;
14
+ private _namespace?;
15
+ constructor(options?: KeyvCacheableMemoryOptions);
16
+ get namespace(): string | undefined;
17
+ set namespace(value: string | undefined);
18
+ get store(): CacheableMemory;
19
+ get<Value>(key: string): Promise<StoredData<Value> | undefined>;
20
+ getMany<Value>(keys: string[]): Promise<Array<StoredData<Value | undefined>>>;
21
+ set(key: string, value: any, ttl?: number): Promise<void>;
22
+ setMany(values: Array<{
23
+ key: string;
24
+ value: any;
25
+ ttl?: number;
26
+ }>): Promise<void>;
27
+ delete(key: string): Promise<boolean>;
28
+ deleteMany?(key: string[]): Promise<boolean>;
29
+ clear(): Promise<void>;
30
+ has?(key: string): Promise<boolean>;
31
+ on(event: string, listener: (...arguments_: any[]) => void): this;
32
+ getStore(namespace?: string): CacheableMemory;
33
+ }
34
+ /**
35
+ * Creates a new Keyv instance with a new KeyvCacheableMemory store. This also removes the serialize/deserialize methods from the Keyv instance for optimization.
36
+ * @param options
37
+ * @returns
38
+ */
39
+ declare function createKeyv(options?: KeyvCacheableMemoryOptions): Keyv;
5
40
 
6
41
  type StoreHashAlgorithmFunction = (key: string, storeHashSize: number) => number;
7
42
  /**
@@ -267,4 +302,4 @@ declare class CacheableMemory extends Hookified {
267
302
  private hasExpired;
268
303
  }
269
304
 
270
- export { CacheableMemory, type CacheableMemoryOptions, type SetOptions, type StoreHashAlgorithmFunction, defaultStoreHashSize, maximumMapSize };
305
+ export { CacheableMemory, type CacheableMemoryOptions, KeyvCacheableMemory, type KeyvCacheableMemoryOptions, type SetOptions, type StoreHashAlgorithmFunction, createKeyv, defaultStoreHashSize, maximumMapSize };