@adonisjs/cache 2.0.1-next.0 → 2.0.1-next.2

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.
@@ -1,87 +1,64 @@
1
- import {
2
- __decorateClass
3
- } from "../chunk-ADS4GRIL.js";
4
-
5
- // commands/cache_clear.ts
6
- import { args, BaseCommand, flags } from "@adonisjs/core/ace";
1
+ import { t as __decorate } from "../decorate-DWG6H_IM.js";
2
+ import { BaseCommand, args, flags } from "@adonisjs/core/ace";
7
3
  var CacheClear = class extends BaseCommand {
8
- static commandName = "cache:clear";
9
- static description = "Clear the application cache";
10
- static options = {
11
- startApp: true
12
- };
13
- /**
14
- * Prompts to take consent when clearing the cache in production
15
- */
16
- async #takeProductionConsent() {
17
- const question = "You are in production environment. Want to continue clearing the cache?";
18
- try {
19
- return await this.prompt.confirm(question);
20
- } catch (error) {
21
- return false;
22
- }
23
- }
24
- /**
25
- * Check if the given cache exist
26
- */
27
- #cacheExists(cache, cacheName) {
28
- try {
29
- cache.use(cacheName);
30
- return true;
31
- } catch (error) {
32
- return false;
33
- }
34
- }
35
- /**
36
- * Handle command
37
- */
38
- async run() {
39
- const cache = await this.app.container.make("cache.manager");
40
- this.store = this.store || cache.defaultStoreName;
41
- if (!this.#cacheExists(cache, this.store)) {
42
- this.logger.error(
43
- `"${this.store}" is not a valid cache store. Double check config/cache.ts file`
44
- );
45
- this.exitCode = 1;
46
- return;
47
- }
48
- if (this.namespace && this.tags && this.tags.length > 0) {
49
- this.logger.error(
50
- "Cannot use --namespace and --tags options together. Please choose one or the other."
51
- );
52
- this.exitCode = 1;
53
- return;
54
- }
55
- if (this.app.inProduction) {
56
- const shouldClear = await this.#takeProductionConsent();
57
- if (!shouldClear) return;
58
- }
59
- const cacheHandler = cache.use(this.store);
60
- if (this.tags && this.tags.length > 0) {
61
- await cacheHandler.deleteByTag({ tags: this.tags });
62
- this.logger.success(
63
- `Invalidated tags [${this.tags.join(", ")}] for "${this.store}" cache successfully`
64
- );
65
- } else if (this.namespace) {
66
- await cacheHandler.namespace(this.namespace).clear();
67
- this.logger.success(
68
- `Cleared namespace "${this.namespace}" for "${this.store}" cache successfully`
69
- );
70
- } else {
71
- await cacheHandler.clear();
72
- this.logger.success(`Cleared "${this.store}" cache successfully`);
73
- }
74
- }
75
- };
76
- __decorateClass([
77
- args.string({ description: "Define a custom cache store to clear", required: false })
78
- ], CacheClear.prototype, "store", 2);
79
- __decorateClass([
80
- flags.string({ description: "Select a cache namespace to clear", alias: "n" })
81
- ], CacheClear.prototype, "namespace", 2);
82
- __decorateClass([
83
- flags.array({ description: "Specify tags to invalidate", alias: "t" })
84
- ], CacheClear.prototype, "tags", 2);
85
- export {
86
- CacheClear as default
4
+ static commandName = "cache:clear";
5
+ static description = "Clear the application cache";
6
+ static options = { startApp: true };
7
+ async #takeProductionConsent() {
8
+ const question = "You are in production environment. Want to continue clearing the cache?";
9
+ try {
10
+ return await this.prompt.confirm(question);
11
+ } catch (error) {
12
+ return false;
13
+ }
14
+ }
15
+ #cacheExists(cache, cacheName) {
16
+ try {
17
+ cache.use(cacheName);
18
+ return true;
19
+ } catch (error) {
20
+ return false;
21
+ }
22
+ }
23
+ async run() {
24
+ const cache = await this.app.container.make("cache.manager");
25
+ this.store = this.store || cache.defaultStoreName;
26
+ if (!this.#cacheExists(cache, this.store)) {
27
+ this.logger.error(`"${this.store}" is not a valid cache store. Double check config/cache.ts file`);
28
+ this.exitCode = 1;
29
+ return;
30
+ }
31
+ if (this.namespace && this.tags && this.tags.length > 0) {
32
+ this.logger.error("Cannot use --namespace and --tags options together. Please choose one or the other.");
33
+ this.exitCode = 1;
34
+ return;
35
+ }
36
+ if (this.app.inProduction) {
37
+ if (!await this.#takeProductionConsent()) return;
38
+ }
39
+ const cacheHandler = cache.use(this.store);
40
+ if (this.tags && this.tags.length > 0) {
41
+ await cacheHandler.deleteByTag({ tags: this.tags });
42
+ this.logger.success(`Invalidated tags [${this.tags.join(", ")}] for "${this.store}" cache successfully`);
43
+ } else if (this.namespace) {
44
+ await cacheHandler.namespace(this.namespace).clear();
45
+ this.logger.success(`Cleared namespace "${this.namespace}" for "${this.store}" cache successfully`);
46
+ } else {
47
+ await cacheHandler.clear();
48
+ this.logger.success(`Cleared "${this.store}" cache successfully`);
49
+ }
50
+ }
87
51
  };
52
+ __decorate([args.string({
53
+ description: "Define a custom cache store to clear",
54
+ required: false
55
+ })], CacheClear.prototype, "store", void 0);
56
+ __decorate([flags.string({
57
+ description: "Select a cache namespace to clear",
58
+ alias: "n"
59
+ })], CacheClear.prototype, "namespace", void 0);
60
+ __decorate([flags.array({
61
+ description: "Specify tags to invalidate",
62
+ alias: "t"
63
+ })], CacheClear.prototype, "tags", void 0);
64
+ export { CacheClear as default };
@@ -1,69 +1,43 @@
1
- import {
2
- __decorateClass
3
- } from "../chunk-ADS4GRIL.js";
4
-
5
- // commands/cache_delete.ts
6
- import { args, BaseCommand } from "@adonisjs/core/ace";
1
+ import { t as __decorate } from "../decorate-DWG6H_IM.js";
2
+ import { BaseCommand, args } from "@adonisjs/core/ace";
7
3
  var CacheDelete = class extends BaseCommand {
8
- static commandName = "cache:delete";
9
- static description = "Delete a specific cache entry by key";
10
- static options = {
11
- startApp: true
12
- };
13
- /**
14
- * Prompts to take consent when deleting cache entry in production
15
- */
16
- async #takeProductionConsent() {
17
- const question = `You are in production environment. Want to continue deleting cache key "${this.key}"?`;
18
- try {
19
- return await this.prompt.confirm(question);
20
- } catch (error) {
21
- return false;
22
- }
23
- }
24
- /**
25
- * Check if the given cache exist
26
- */
27
- #cacheExists(cache, cacheName) {
28
- try {
29
- cache.use(cacheName);
30
- return true;
31
- } catch (error) {
32
- return false;
33
- }
34
- }
35
- /**
36
- * Handle command
37
- */
38
- async run() {
39
- const cache = await this.app.container.make("cache.manager");
40
- this.store = this.store || cache.defaultStoreName;
41
- if (!this.#cacheExists(cache, this.store)) {
42
- this.logger.error(
43
- `"${this.store}" is not a valid cache store. Double check config/cache.ts file`
44
- );
45
- this.exitCode = 1;
46
- return;
47
- }
48
- if (this.app.inProduction) {
49
- const shouldDelete = await this.#takeProductionConsent();
50
- if (!shouldDelete) return;
51
- }
52
- const cacheHandler = cache.use(this.store);
53
- const deleted = await cacheHandler.delete({ key: this.key });
54
- if (deleted) {
55
- this.logger.success(`Deleted cache key "${this.key}" from "${this.store}" cache successfully`);
56
- } else {
57
- this.logger.warning(`Cache key "${this.key}" not found in "${this.store}" cache`);
58
- }
59
- }
60
- };
61
- __decorateClass([
62
- args.string({ description: "The cache key to delete" })
63
- ], CacheDelete.prototype, "key", 2);
64
- __decorateClass([
65
- args.string({ description: "Define a custom cache store to delete from", required: false })
66
- ], CacheDelete.prototype, "store", 2);
67
- export {
68
- CacheDelete as default
4
+ static commandName = "cache:delete";
5
+ static description = "Delete a specific cache entry by key";
6
+ static options = { startApp: true };
7
+ async #takeProductionConsent() {
8
+ const question = `You are in production environment. Want to continue deleting cache key "${this.key}"?`;
9
+ try {
10
+ return await this.prompt.confirm(question);
11
+ } catch (error) {
12
+ return false;
13
+ }
14
+ }
15
+ #cacheExists(cache, cacheName) {
16
+ try {
17
+ cache.use(cacheName);
18
+ return true;
19
+ } catch (error) {
20
+ return false;
21
+ }
22
+ }
23
+ async run() {
24
+ const cache = await this.app.container.make("cache.manager");
25
+ this.store = this.store || cache.defaultStoreName;
26
+ if (!this.#cacheExists(cache, this.store)) {
27
+ this.logger.error(`"${this.store}" is not a valid cache store. Double check config/cache.ts file`);
28
+ this.exitCode = 1;
29
+ return;
30
+ }
31
+ if (this.app.inProduction) {
32
+ if (!await this.#takeProductionConsent()) return;
33
+ }
34
+ if (await cache.use(this.store).delete({ key: this.key })) this.logger.success(`Deleted cache key "${this.key}" from "${this.store}" cache successfully`);
35
+ else this.logger.warning(`Cache key "${this.key}" not found in "${this.store}" cache`);
36
+ }
69
37
  };
38
+ __decorate([args.string({ description: "The cache key to delete" })], CacheDelete.prototype, "key", void 0);
39
+ __decorate([args.string({
40
+ description: "Define a custom cache store to delete from",
41
+ required: false
42
+ })], CacheDelete.prototype, "store", void 0);
43
+ export { CacheDelete as default };
@@ -1,62 +1,42 @@
1
- import {
2
- __decorateClass
3
- } from "../chunk-ADS4GRIL.js";
4
-
5
- // commands/cache_prune.ts
6
- import { args, BaseCommand } from "@adonisjs/core/ace";
1
+ import { t as __decorate } from "../decorate-DWG6H_IM.js";
2
+ import { BaseCommand, args } from "@adonisjs/core/ace";
7
3
  var CachePrune = class extends BaseCommand {
8
- static commandName = "cache:prune";
9
- static description = "Remove expired cache entries from the selected store. This command is only useful for stores without native TTL support, like Database or File drivers.";
10
- static options = {
11
- startApp: true
12
- };
13
- /**
14
- * Prompts to take consent when pruning the cache in production
15
- */
16
- async #takeProductionConsent() {
17
- const question = "You are in production environment. Want to continue pruning expired cache entries?";
18
- try {
19
- return await this.prompt.confirm(question);
20
- } catch (error) {
21
- return false;
22
- }
23
- }
24
- /**
25
- * Check if the given cache exist
26
- */
27
- #cacheExists(cache, cacheName) {
28
- try {
29
- cache.use(cacheName);
30
- return true;
31
- } catch (error) {
32
- return false;
33
- }
34
- }
35
- /**
36
- * Handle command
37
- */
38
- async run() {
39
- const cache = await this.app.container.make("cache.manager");
40
- this.store = this.store || cache.defaultStoreName;
41
- if (!this.#cacheExists(cache, this.store)) {
42
- this.logger.error(
43
- `"${this.store}" is not a valid cache store. Double check config/cache.ts file`
44
- );
45
- this.exitCode = 1;
46
- return;
47
- }
48
- if (this.app.inProduction) {
49
- const shouldPrune = await this.#takeProductionConsent();
50
- if (!shouldPrune) return;
51
- }
52
- const cacheHandler = cache.use(this.store);
53
- await cacheHandler.prune();
54
- this.logger.success(`Pruned expired entries from "${this.store}" cache successfully`);
55
- }
56
- };
57
- __decorateClass([
58
- args.string({ description: "Define a custom cache store to prune", required: false })
59
- ], CachePrune.prototype, "store", 2);
60
- export {
61
- CachePrune as default
4
+ static commandName = "cache:prune";
5
+ static description = "Remove expired cache entries from the selected store. This command is only useful for stores without native TTL support, like Database or File drivers.";
6
+ static options = { startApp: true };
7
+ async #takeProductionConsent() {
8
+ const question = "You are in production environment. Want to continue pruning expired cache entries?";
9
+ try {
10
+ return await this.prompt.confirm(question);
11
+ } catch (error) {
12
+ return false;
13
+ }
14
+ }
15
+ #cacheExists(cache, cacheName) {
16
+ try {
17
+ cache.use(cacheName);
18
+ return true;
19
+ } catch (error) {
20
+ return false;
21
+ }
22
+ }
23
+ async run() {
24
+ const cache = await this.app.container.make("cache.manager");
25
+ this.store = this.store || cache.defaultStoreName;
26
+ if (!this.#cacheExists(cache, this.store)) {
27
+ this.logger.error(`"${this.store}" is not a valid cache store. Double check config/cache.ts file`);
28
+ this.exitCode = 1;
29
+ return;
30
+ }
31
+ if (this.app.inProduction) {
32
+ if (!await this.#takeProductionConsent()) return;
33
+ }
34
+ await cache.use(this.store).prune();
35
+ this.logger.success(`Pruned expired entries from "${this.store}" cache successfully`);
36
+ }
62
37
  };
38
+ __decorate([args.string({
39
+ description: "Define a custom cache store to prune",
40
+ required: false
41
+ })], CachePrune.prototype, "store", void 0);
42
+ export { CachePrune as default };
@@ -0,0 +1,7 @@
1
+ function __decorate(decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ }
7
+ export { __decorate as t };
package/build/index.d.ts CHANGED
@@ -3,3 +3,4 @@ export { store } from './src/store.ts';
3
3
  export { configure } from './configure.ts';
4
4
  export { defineConfig } from './src/define_config.ts';
5
5
  export { drivers } from './src/drivers.ts';
6
+ export { tracingChannels } from 'bentocache';
package/build/index.js CHANGED
@@ -1,227 +1,151 @@
1
- import "./chunk-ADS4GRIL.js";
2
-
3
- // index.ts
4
- export * from "bentocache";
5
-
6
- // src/store.ts
7
- import { bentostore } from "bentocache";
1
+ import { bentostore, tracingChannels } from "bentocache";
8
2
  import { configProvider } from "@adonisjs/core";
3
+ import { RuntimeException } from "@adonisjs/core/exceptions";
4
+ export * from "bentocache";
9
5
  function store(options) {
10
- return new Store(options);
6
+ return new Store(options);
11
7
  }
12
8
  var Store = class {
13
- #baseOptions = {};
14
- #l1;
15
- #l2;
16
- #bus;
17
- constructor(baseOptions = {}) {
18
- this.#baseOptions = baseOptions;
19
- }
20
- /**
21
- * Add a L1 layer to your store. This is usually a memory driver
22
- * for fast access purposes.
23
- */
24
- useL1Layer(driver) {
25
- this.#l1 = driver;
26
- return this;
27
- }
28
- /**
29
- * Add a L2 layer to your store. This is usually something
30
- * distributed like Redis, DynamoDB, Sql database, etc.
31
- */
32
- useL2Layer(driver) {
33
- this.#l2 = driver;
34
- return this;
35
- }
36
- /**
37
- * Add a bus to your store. It will be used to synchronize L1 layers between
38
- * different instances of your application.
39
- */
40
- useBus(bus) {
41
- this.#bus = bus;
42
- return this;
43
- }
44
- /**
45
- * Create a config provider for the store
46
- */
47
- entry() {
48
- return configProvider.create(async (app) => {
49
- const storeInstance = bentostore(this.#baseOptions);
50
- if (this.#l1) storeInstance.useL1Layer(await this.#l1?.resolver(app));
51
- if (this.#l2) storeInstance.useL2Layer(await this.#l2?.resolver(app));
52
- if (this.#bus) storeInstance.useBus(await this.#bus?.resolver(app));
53
- return storeInstance;
54
- });
55
- }
9
+ #baseOptions = {};
10
+ #l1;
11
+ #l2;
12
+ #bus;
13
+ constructor(baseOptions = {}) {
14
+ this.#baseOptions = baseOptions;
15
+ }
16
+ useL1Layer(driver) {
17
+ this.#l1 = driver;
18
+ return this;
19
+ }
20
+ useL2Layer(driver) {
21
+ this.#l2 = driver;
22
+ return this;
23
+ }
24
+ useBus(bus) {
25
+ this.#bus = bus;
26
+ return this;
27
+ }
28
+ entry() {
29
+ return configProvider.create(async (app) => {
30
+ const storeInstance = bentostore(this.#baseOptions);
31
+ if (this.#l1) storeInstance.useL1Layer(await this.#l1?.resolver(app));
32
+ if (this.#l2) storeInstance.useL2Layer(await this.#l2?.resolver(app));
33
+ if (this.#bus) storeInstance.useBus(await this.#bus?.resolver(app));
34
+ return storeInstance;
35
+ });
36
+ }
56
37
  };
57
-
58
- // stubs/main.ts
59
- var stubsRoot = import.meta.dirname;
60
-
61
- // configure.ts
62
- var DRIVERS_INFO = {
63
- file: {},
64
- redis: {},
65
- database: {},
66
- dynamodb: {
67
- envValidations: {
68
- AWS_ACCESS_KEY_ID: `Env.schema.string()`,
69
- AWS_SECRET_ACCESS_KEY: `Env.schema.string()`,
70
- AWS_REGION: `Env.schema.string()`,
71
- DYNAMODB_ENDPOINT: `Env.schema.string()`
72
- },
73
- envVars: {
74
- AWS_ACCESS_KEY_ID: "",
75
- AWS_SECRET_ACCESS_KEY: "",
76
- AWS_REGION: "",
77
- DYNAMODB_ENDPOINT: ""
78
- }
79
- }
38
+ const stubsRoot = import.meta.dirname;
39
+ const DRIVERS_INFO = {
40
+ file: {},
41
+ redis: {},
42
+ database: {},
43
+ dynamodb: {
44
+ envValidations: {
45
+ AWS_ACCESS_KEY_ID: `Env.schema.string()`,
46
+ AWS_SECRET_ACCESS_KEY: `Env.schema.string()`,
47
+ AWS_REGION: `Env.schema.string()`,
48
+ DYNAMODB_ENDPOINT: `Env.schema.string()`
49
+ },
50
+ envVars: {
51
+ AWS_ACCESS_KEY_ID: "",
52
+ AWS_SECRET_ACCESS_KEY: "",
53
+ AWS_REGION: "",
54
+ DYNAMODB_ENDPOINT: ""
55
+ }
56
+ }
80
57
  };
81
58
  async function configure(command) {
82
- const driver = await command.prompt.choice(
83
- "Select the cache driver you plan to use",
84
- ["redis", "file", "database", "dynamodb"],
85
- {
86
- hint: "You can always change it later"
87
- }
88
- );
89
- const codemods = await command.createCodemods();
90
- await codemods.updateRcFile((rcFile) => {
91
- rcFile.addProvider("@adonisjs/cache/cache_provider").addCommand("@adonisjs/cache/commands");
92
- });
93
- const { envVars, envValidations } = DRIVERS_INFO[driver];
94
- if (envVars) {
95
- await codemods.defineEnvVariables(envVars);
96
- }
97
- if (envValidations) {
98
- await codemods.defineEnvValidations({ variables: envValidations });
99
- }
100
- await codemods.makeUsingStub(stubsRoot, "config.stub", { driver });
101
- if (driver === "database") {
102
- await codemods.makeUsingStub(stubsRoot, "migration.stub", {
103
- entity: command.app.generators.createEntity("cache"),
104
- migration: {
105
- folder: "database/migrations",
106
- fileName: `${(/* @__PURE__ */ new Date()).getTime()}_create_cache_table.ts`
107
- }
108
- });
109
- }
59
+ const driver = await command.prompt.choice("Select the cache driver you plan to use", [
60
+ "redis",
61
+ "file",
62
+ "database",
63
+ "dynamodb"
64
+ ], { hint: "You can always change it later" });
65
+ const codemods = await command.createCodemods();
66
+ await codemods.updateRcFile((rcFile) => {
67
+ rcFile.addProvider("@adonisjs/cache/cache_provider").addCommand("@adonisjs/cache/commands");
68
+ });
69
+ const { envVars, envValidations } = DRIVERS_INFO[driver];
70
+ if (envVars) await codemods.defineEnvVariables(envVars);
71
+ if (envValidations) await codemods.defineEnvValidations({ variables: envValidations });
72
+ await codemods.makeUsingStub(stubsRoot, "config.stub", { driver });
73
+ if (driver === "database") await codemods.makeUsingStub(stubsRoot, "migration.stub", {
74
+ entity: command.app.generators.createEntity("cache"),
75
+ migration: {
76
+ folder: "database/migrations",
77
+ fileName: `${(/* @__PURE__ */ new Date()).getTime()}_create_cache_table.ts`
78
+ }
79
+ });
110
80
  }
111
-
112
- // src/define_config.ts
113
81
  function defineConfig(config) {
114
- return config;
82
+ return config;
115
83
  }
116
-
117
- // src/drivers.ts
118
- import { configProvider as configProvider2 } from "@adonisjs/core";
119
- import { RuntimeException } from "@adonisjs/core/exceptions";
120
- var drivers = {
121
- /**
122
- * Redis driver for L2 layer
123
- * You must install @adonisjs/redis to use this driver
124
- */
125
- redis(config) {
126
- return configProvider2.create(async (app) => {
127
- const redis = await app.container.make("redis");
128
- const { redisDriver } = await import("bentocache/drivers/redis");
129
- const redisConnection = redis.connection(config.connectionName);
130
- return redisDriver({
131
- connection: redisConnection.ioConnection,
132
- prefix: config.prefix || "bentocache"
133
- });
134
- });
135
- },
136
- /**
137
- * Redis driver for the sync bus
138
- * You must install @adonisjs/redis to use this driver
139
- */
140
- redisBus(config) {
141
- return configProvider2.create(async (app) => {
142
- const redis = await app.container.make("redis");
143
- const { redisBusDriver } = await import("bentocache/drivers/redis");
144
- const redisConnection = redis.connection(config.connectionName);
145
- return redisBusDriver({
146
- connection: redisConnection.ioConnection.options,
147
- retryQueue: config.retryQueue
148
- });
149
- });
150
- },
151
- /**
152
- * Memory driver for L1 layer
153
- */
154
- memory(config) {
155
- return configProvider2.create(async () => {
156
- const { memoryDriver } = await import("bentocache/drivers/memory");
157
- return memoryDriver(config);
158
- });
159
- },
160
- /**
161
- * Database driver for L2 layer
162
- * You must install @adonisjs/lucid to use this driver
163
- */
164
- database(config) {
165
- return configProvider2.create(async (app) => {
166
- const db = await app.container.make("lucid.db");
167
- const connectionName = config?.connectionName || db.primaryConnectionName;
168
- const connection = db.manager.get(connectionName);
169
- if (!connection) {
170
- throw new RuntimeException(
171
- `Invalid connection name "${connectionName}" referenced by "config/cache.ts" file. First register the connection inside "config/database.ts" file`
172
- );
173
- }
174
- const { knexDriver } = await import("bentocache/drivers/knex");
175
- return knexDriver({
176
- connection: db.connection(connectionName).getWriteClient(),
177
- autoCreateTable: config?.autoCreateTable ?? true,
178
- tableName: config?.tableName || "bentocache",
179
- pruneInterval: config?.pruneInterval ?? false,
180
- prefix: config?.prefix || "bentocache"
181
- });
182
- });
183
- },
184
- /**
185
- * DynamoDB driver for L2 layer
186
- * You must install @aws-sdk/client-dynamodb to use this driver
187
- */
188
- dynamodb(config) {
189
- return configProvider2.create(async () => {
190
- const { dynamoDbDriver } = await import("bentocache/drivers/dynamodb");
191
- return dynamoDbDriver(config);
192
- });
193
- },
194
- /**
195
- * File driver for L2 layer
196
- */
197
- file(config) {
198
- return configProvider2.create(async () => {
199
- const { fileDriver } = await import("bentocache/drivers/file");
200
- return fileDriver(config);
201
- });
202
- },
203
- /**
204
- * Kysely driver for L2 layer
205
- */
206
- kysely(config) {
207
- return configProvider2.create(async () => {
208
- const { kyselyDriver } = await import("bentocache/drivers/kysely");
209
- return kyselyDriver(config);
210
- });
211
- },
212
- /**
213
- * Orchid driver for L2 layer
214
- */
215
- orchid(config) {
216
- return configProvider2.create(async () => {
217
- const { orchidDriver } = await import("bentocache/drivers/orchid");
218
- return orchidDriver(config);
219
- });
220
- }
221
- };
222
- export {
223
- configure,
224
- defineConfig,
225
- drivers,
226
- store
84
+ const drivers = {
85
+ redis(config) {
86
+ return configProvider.create(async (app) => {
87
+ const redis = await app.container.make("redis");
88
+ const { redisDriver } = await import("bentocache/drivers/redis");
89
+ return redisDriver({
90
+ connection: redis.connection(config.connectionName).ioConnection,
91
+ prefix: config.prefix || "bentocache"
92
+ });
93
+ });
94
+ },
95
+ redisBus(config) {
96
+ return configProvider.create(async (app) => {
97
+ const redis = await app.container.make("redis");
98
+ const { redisBusDriver } = await import("bentocache/drivers/redis");
99
+ return redisBusDriver({
100
+ connection: redis.connection(config.connectionName).ioConnection.options,
101
+ retryQueue: config.retryQueue
102
+ });
103
+ });
104
+ },
105
+ memory(config) {
106
+ return configProvider.create(async () => {
107
+ const { memoryDriver } = await import("bentocache/drivers/memory");
108
+ return memoryDriver(config);
109
+ });
110
+ },
111
+ database(config) {
112
+ return configProvider.create(async (app) => {
113
+ const db = await app.container.make("lucid.db");
114
+ const connectionName = config?.connectionName || db.primaryConnectionName;
115
+ if (!db.manager.get(connectionName)) throw new RuntimeException(`Invalid connection name "${connectionName}" referenced by "config/cache.ts" file. First register the connection inside "config/database.ts" file`);
116
+ const { knexDriver } = await import("bentocache/drivers/knex");
117
+ return knexDriver({
118
+ connection: db.connection(connectionName).getWriteClient(),
119
+ autoCreateTable: config?.autoCreateTable ?? true,
120
+ tableName: config?.tableName || "bentocache",
121
+ pruneInterval: config?.pruneInterval ?? false,
122
+ prefix: config?.prefix || "bentocache"
123
+ });
124
+ });
125
+ },
126
+ dynamodb(config) {
127
+ return configProvider.create(async () => {
128
+ const { dynamoDbDriver } = await import("bentocache/drivers/dynamodb");
129
+ return dynamoDbDriver(config);
130
+ });
131
+ },
132
+ file(config) {
133
+ return configProvider.create(async () => {
134
+ const { fileDriver } = await import("bentocache/drivers/file");
135
+ return fileDriver(config);
136
+ });
137
+ },
138
+ kysely(config) {
139
+ return configProvider.create(async () => {
140
+ const { kyselyDriver } = await import("bentocache/drivers/kysely");
141
+ return kyselyDriver(config);
142
+ });
143
+ },
144
+ orchid(config) {
145
+ return configProvider.create(async () => {
146
+ const { orchidDriver } = await import("bentocache/drivers/orchid");
147
+ return orchidDriver(config);
148
+ });
149
+ }
227
150
  };
151
+ export { configure, defineConfig, drivers, store, tracingChannels };
@@ -34,7 +34,11 @@ export default class CacheProvider {
34
34
  /**
35
35
  * Register bindings
36
36
  */
37
- register(): Promise<void>;
37
+ register(): void;
38
+ /**
39
+ * Boot provider
40
+ */
41
+ boot(): Promise<void>;
38
42
  /**
39
43
  * Gracefully shutdown connections when app goes down
40
44
  */
@@ -1,92 +1,57 @@
1
- import "../chunk-ADS4GRIL.js";
2
-
3
- // src/bindings/repl.ts
1
+ import { debuglog } from "node:util";
4
2
  function setupReplState(repl, key, value) {
5
- repl.server.context[key] = value;
6
- repl.notify(
7
- `Loaded ${key} module. You can access it using the "${repl.colors.underline(key)}" variable`
8
- );
3
+ repl.server.context[key] = value;
4
+ repl.notify(`Loaded ${key} module. You can access it using the "${repl.colors.underline(key)}" variable`);
9
5
  }
10
6
  function defineReplBindings(app, Repl) {
11
- Repl.addMethod(
12
- "loadCache",
13
- async (repl) => setupReplState(repl, "cache", await app.container.make("cache.manager")),
14
- { description: 'Load cache provider to the "cache" property' }
15
- );
7
+ Repl.addMethod("loadCache", async (repl) => setupReplState(repl, "cache", await app.container.make("cache.manager")), { description: "Load cache provider to the \"cache\" property" });
16
8
  }
17
-
18
- // src/debug.ts
19
- import { debuglog } from "util";
20
9
  var debug_default = debuglog("adonisjs:cache");
21
-
22
- // src/bindings/edge.ts
23
10
  async function registerViewBindings(manager) {
24
- const edge = await import("edge.js");
25
- debug_default("detected edge installation. Registering cache global helpers");
26
- edge.default.global("cache", manager);
11
+ const edge = await import("edge.js");
12
+ debug_default("detected edge installation. Registering cache global helpers");
13
+ edge.default.global("cache", manager);
27
14
  }
28
-
29
- // providers/cache_provider.ts
30
15
  var CacheProvider = class {
31
- constructor(app) {
32
- this.app = app;
33
- }
34
- /**
35
- * Register the cache manager to the container
36
- */
37
- async #registerCacheManager() {
38
- const cacheConfig = this.app.config.get("cache");
39
- this.app.container.singleton("cache.manager", async () => {
40
- const { BentoCache } = await import("bentocache");
41
- const emitter = await this.app.container.make("emitter");
42
- const resolvedStores = Object.entries(cacheConfig.stores).map(async ([name, store]) => {
43
- return [name, await store.entry().resolver(this.app)];
44
- });
45
- return new BentoCache({
46
- ...cacheConfig,
47
- emitter,
48
- default: cacheConfig.default,
49
- stores: Object.fromEntries(await Promise.all(resolvedStores))
50
- });
51
- });
52
- }
53
- /**
54
- * Register REPL bindings
55
- */
56
- async #registerReplBindings() {
57
- if (this.app.getEnvironment() !== "repl") {
58
- return;
59
- }
60
- const repl = await this.app.container.make("repl");
61
- defineReplBindings(this.app, repl);
62
- }
63
- /**
64
- * Register edge bindings
65
- */
66
- async #registerEdgeBindings() {
67
- if (!this.app.usingEdgeJS) return;
68
- const manager = await this.app.container.make("cache.manager");
69
- await registerViewBindings(manager);
70
- }
71
- /**
72
- * Register bindings
73
- */
74
- async register() {
75
- await this.#registerCacheManager();
76
- await this.#registerReplBindings();
77
- await this.#registerEdgeBindings();
78
- }
79
- /**
80
- * Gracefully shutdown connections when app goes down
81
- */
82
- async shutdown() {
83
- try {
84
- const cache = await this.app.container.make("cache.manager");
85
- await cache.disconnectAll();
86
- } catch (_e) {
87
- }
88
- }
89
- };
90
- export {
91
- CacheProvider as default
16
+ constructor(app) {
17
+ this.app = app;
18
+ }
19
+ #registerCacheManager() {
20
+ const cacheConfig = this.app.config.get("cache");
21
+ this.app.container.singleton("cache.manager", async () => {
22
+ const { BentoCache } = await import("bentocache");
23
+ const emitter = await this.app.container.make("emitter");
24
+ const resolvedStores = Object.entries(cacheConfig.stores).map(async ([name, store]) => {
25
+ return [name, await store.entry().resolver(this.app)];
26
+ });
27
+ return new BentoCache({
28
+ ...cacheConfig,
29
+ emitter,
30
+ default: cacheConfig.default,
31
+ stores: Object.fromEntries(await Promise.all(resolvedStores))
32
+ });
33
+ });
34
+ }
35
+ async #registerReplBindings() {
36
+ if (this.app.getEnvironment() !== "repl") return;
37
+ const repl = await this.app.container.make("repl");
38
+ defineReplBindings(this.app, repl);
39
+ }
40
+ async #registerEdgeBindings() {
41
+ if (!this.app.usingEdgeJS) return;
42
+ await registerViewBindings(await this.app.container.make("cache.manager"));
43
+ }
44
+ register() {
45
+ this.#registerCacheManager();
46
+ }
47
+ async boot() {
48
+ await this.#registerEdgeBindings();
49
+ await this.#registerReplBindings();
50
+ }
51
+ async shutdown() {
52
+ try {
53
+ await (await this.app.container.make("cache.manager")).disconnectAll();
54
+ } catch (_e) {}
55
+ }
92
56
  };
57
+ export { CacheProvider as default };
@@ -1,11 +1,6 @@
1
- import "../chunk-ADS4GRIL.js";
2
-
3
- // services/main.ts
4
1
  import app from "@adonisjs/core/services/app";
5
- var cache;
2
+ let cache;
6
3
  await app.booted(async () => {
7
- cache = await app.container.make("cache.manager");
4
+ cache = await app.container.make("cache.manager");
8
5
  });
9
- export {
10
- cache as default
11
- };
6
+ export { cache as default };
@@ -1,2 +1,2 @@
1
- declare const _default: import("util").DebugLogger;
1
+ declare const _default: import("node:util").DebugLogger;
2
2
  export default _default;
@@ -1,2 +1,2 @@
1
- // src/types.ts
2
1
  export * from "bentocache/types";
2
+ export {};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@adonisjs/cache",
3
3
  "description": "Official caching module for AdonisJS framework",
4
- "version": "2.0.1-next.0",
4
+ "version": "2.0.1-next.2",
5
5
  "engines": {
6
6
  "node": ">=22.0.0"
7
7
  },
@@ -31,47 +31,47 @@
31
31
  "pretest": "npm run lint",
32
32
  "test": "c8 npm run quick:test",
33
33
  "prebuild": "npm run lint && npm run clean",
34
- "build": "tsup-node && tsc --emitDeclarationOnly --declaration",
34
+ "build": "tsdown && tsc --emitDeclarationOnly --declaration",
35
35
  "postbuild": "npm run copy:templates && npm run index:commands",
36
36
  "release": "npx release-it",
37
37
  "version": "npm run build",
38
38
  "prepublishOnly": "npm run build"
39
39
  },
40
40
  "devDependencies": {
41
- "@adonisjs/assembler": "^8.0.0-next.19",
42
- "@adonisjs/core": "^7.0.0-next.13",
43
- "@adonisjs/eslint-config": "^3.0.0-next.4",
44
- "@adonisjs/lucid": "^22.0.0-next.1",
41
+ "@adonisjs/assembler": "^8.0.0-next.32",
42
+ "@adonisjs/core": "^7.0.0-next.28",
43
+ "@adonisjs/eslint-config": "^3.0.0-next.9",
44
+ "@adonisjs/lucid": "^22.0.0-next.8",
45
45
  "@adonisjs/prettier-config": "^1.4.5",
46
- "@adonisjs/redis": "^10.0.0-next.1",
46
+ "@adonisjs/redis": "^10.0.0-next.2",
47
47
  "@adonisjs/tsconfig": "^2.0.0-next.3",
48
- "@japa/assert": "^4.1.1",
49
- "@japa/expect-type": "^2.0.3",
50
- "@japa/file-system": "^2.3.2",
51
- "@japa/runner": "^4.4.0",
52
- "@japa/snapshot": "^2.0.9",
53
- "@poppinss/ts-exec": "^1.4.1",
54
- "@release-it/conventional-changelog": "^10.0.2",
55
- "@types/node": "~24.10.1",
56
- "better-sqlite3": "^12.5.0",
48
+ "@japa/assert": "^4.2.0",
49
+ "@japa/expect-type": "^2.0.4",
50
+ "@japa/file-system": "^3.0.0",
51
+ "@japa/runner": "^5.3.0",
52
+ "@japa/snapshot": "^2.0.10",
53
+ "@poppinss/ts-exec": "^1.4.4",
54
+ "@release-it/conventional-changelog": "^10.0.5",
55
+ "@types/node": "~25.2.2",
56
+ "better-sqlite3": "^12.6.2",
57
57
  "c8": "^10.1.3",
58
58
  "copyfiles": "^2.4.1",
59
59
  "del-cli": "^7.0.0",
60
- "edge.js": "^6.3.0",
61
- "eslint": "^9.39.1",
62
- "ioredis": "^5.8.2",
60
+ "edge.js": "^6.4.0",
61
+ "eslint": "^9.39.2",
62
+ "ioredis": "^5.9.2",
63
63
  "knex": "^3.1.0",
64
64
  "luxon": "^3.7.2",
65
- "mysql2": "^3.15.3",
66
- "p-event": "^7.0.1",
67
- "pg": "^8.16.3",
68
- "prettier": "^3.7.4",
69
- "release-it": "^19.0.6",
70
- "tsup": "^8.5.1",
65
+ "mysql2": "^3.16.3",
66
+ "p-event": "^7.1.0",
67
+ "pg": "^8.18.0",
68
+ "prettier": "^3.8.1",
69
+ "release-it": "^19.2.4",
70
+ "tsdown": "^0.20.1",
71
71
  "typescript": "~5.9.3"
72
72
  },
73
73
  "dependencies": {
74
- "bentocache": "^1.5.0"
74
+ "bentocache": "^1.6.1"
75
75
  },
76
76
  "peerDependencies": {
77
77
  "@adonisjs/assembler": "^8.0.0-next.19",
@@ -144,7 +144,7 @@
144
144
  "tests/**"
145
145
  ]
146
146
  },
147
- "tsup": {
147
+ "tsdown": {
148
148
  "entry": [
149
149
  "index.ts",
150
150
  "src/types.ts",
@@ -157,9 +157,15 @@
157
157
  "outDir": "./build",
158
158
  "clean": true,
159
159
  "format": "esm",
160
+ "minify": "dce-only",
161
+ "fixedExtension": false,
160
162
  "dts": false,
161
- "sourcemap": false,
162
- "target": "esnext"
163
+ "treeshake": false,
164
+ "sourcemaps": false,
165
+ "target": "esnext",
166
+ "external": [
167
+ "edge.js"
168
+ ]
163
169
  },
164
- "packageManager": "pnpm@10.24.0"
170
+ "packageManager": "pnpm@10.29.2"
165
171
  }
@@ -1,14 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __decorateClass = (decorators, target, key, kind) => {
4
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
5
- for (var i = decorators.length - 1, decorator; i >= 0; i--)
6
- if (decorator = decorators[i])
7
- result = (kind ? decorator(target, key, result) : decorator(result)) || result;
8
- if (kind && result) __defProp(target, key, result);
9
- return result;
10
- };
11
-
12
- export {
13
- __decorateClass
14
- };