@stacksjs/cache 0.69.3 → 0.70.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/base.d.ts ADDED
@@ -0,0 +1,77 @@
1
+ import type { BentoCache } from 'bentocache';
2
+ import type { CacheDriver } from '@stacksjs/types';
3
+ import type { GetOptions } from 'bentocache/types';
4
+
5
+ export declare abstract class BaseCacheDriver implements CacheDriver {
6
+ constructor(protected client: BentoCache<Record<string, any>>) {}
7
+
8
+ async set(key: string, value: string, ttl?: number): Promise<void> {
9
+ const data: { key: string, value: string, gracePeriod?: { enabled: boolean, duration: string } } = {
10
+ key,
11
+ value,
12
+ }
13
+
14
+ if (ttl) {
15
+ data.gracePeriod = {
16
+ enabled: true,
17
+ duration: `${ttl}m`,
18
+ }
19
+ }
20
+
21
+ await this.client.set(data)
22
+ }
23
+
24
+ async setForever(key: string, value: string): Promise<void> {
25
+ await this.client.setForever({
26
+ key,
27
+ value,
28
+ })
29
+ }
30
+
31
+ async get<T>(key: GetOptions<T>): Promise<T> {
32
+ return await this.client.get<T>(key)
33
+ }
34
+
35
+ async getOrSet<T>(key: string, value: T): Promise<T> {
36
+ return await this.client.getOrSet<T>({
37
+ key,
38
+ factory: async () => value,
39
+ })
40
+ }
41
+
42
+ async del(key: string): Promise<void> {
43
+ await this.client.delete({ key })
44
+ }
45
+
46
+ async deleteMany(keys: string[]): Promise<void> {
47
+ await this.client.deleteMany({ keys })
48
+ }
49
+
50
+ async remove(key: string): Promise<void> {
51
+ await this.client.delete({ key })
52
+ }
53
+
54
+ async has(key: string): Promise<boolean> {
55
+ return await this.client.has({ key })
56
+ }
57
+
58
+ async missing(key: string): Promise<boolean> {
59
+ return await this.client.missing({ key })
60
+ }
61
+
62
+ async deleteAll(): Promise<void> {
63
+ await this.client.clear()
64
+ }
65
+
66
+ async clear(): Promise<void> {
67
+ await this.client.clear()
68
+ }
69
+
70
+ async disconnect(): Promise<void> {
71
+ await this.client.disconnect()
72
+ }
73
+
74
+ get bentoCacheClient(): BentoCache<Record<string, any>> {
75
+ return this.client
76
+ }
77
+ }
@@ -1,5 +1,38 @@
1
- import type { CacheDriver } from '@stacksjs/types';
1
+ export declare interface DynamoDBOptions {
2
+ endpoint?: string
3
+ region?: string
4
+ tableName?: string
5
+ accessKeyId?: string
6
+ secretAccessKey?: string
7
+ }
8
+ export declare class DynamoDBCacheDriver extends BaseCacheDriver {
9
+ constructor(options: DynamoDBOptions = {}) {
10
+ const awsAccessKeyId = options.accessKeyId ?? config.cache.drivers?.dynamodb?.key ?? 'dummy'
11
+ const awsSecretAccessKey = options.secretAccessKey ?? config.cache.drivers?.dynamodb?.secret ?? 'dummy'
12
+ const dynamoEndpoint = options.endpoint ?? config.cache.drivers?.dynamodb?.endpoint ?? 'http:
13
+ const tableName = options.tableName ?? config.cache.drivers?.dynamodb?.table ?? 'stacks'
14
+ const region = options.region ?? config.cache.drivers?.dynamodb?.region ?? 'us-east-1'
2
15
 
3
- declare const awsAccessKeyId: unknown;
4
- declare const client: unknown;
5
- export declare const dynamodb: CacheDriver;
16
+ const client = new BentoCache({
17
+ default: 'dynamo',
18
+ stores: {
19
+ dynamo: bentostore().useL2Layer(
20
+ dynamoDbDriver({
21
+ endpoint: dynamoEndpoint,
22
+ region,
23
+ table: {
24
+ name: tableName,
25
+ },
26
+ credentials: {
27
+ accessKeyId: awsAccessKeyId,
28
+ secretAccessKey: awsSecretAccessKey,
29
+ },
30
+ }),
31
+ ),
32
+ },
33
+ })
34
+
35
+ super(client)
36
+ }
37
+ }
38
+ export declare const dynamodb: DynamoDBCacheDriver;
@@ -1,4 +1,22 @@
1
- import type { CacheDriver } from '@stacksjs/types';
1
+ export declare interface FileSystemOptions {
2
+ directory?: string
3
+ pruneInterval?: string
4
+ }
5
+ export declare class FileSystemCacheDriver extends BaseCacheDriver {
6
+ constructor(options: FileSystemOptions = {}) {
7
+ const client = new BentoCache({
8
+ default: 'file',
9
+ stores: {
10
+ file: bentostore().useL2Layer(
11
+ fileDriver({
12
+ directory: options.directory ?? './cache',
13
+ pruneInterval: options.pruneInterval ?? '1h',
14
+ }),
15
+ ),
16
+ },
17
+ })
2
18
 
3
- declare const client: unknown;
4
- export declare const fileSystem: CacheDriver;
19
+ super(client)
20
+ }
21
+ }
22
+ export declare const fileSystem: unknown;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,2 @@
1
- import type { CacheDriver } from '@stacksjs/types';
2
-
3
- declare let driver: unknown;
4
- export declare const cache: CacheDriver;
1
+ export * from './drivers'
2
+ export * as dynamoDbTool from 'dynamodb-tooling'