@adonisjs/cache 2.0.1-next.1 → 2.0.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/build/commands/cache_clear.js +62 -85
- package/build/commands/cache_delete.js +41 -67
- package/build/commands/cache_prune.js +40 -60
- package/build/decorate-DWG6H_IM.js +7 -0
- package/build/index.js +140 -220
- package/build/providers/cache_provider.js +48 -88
- package/build/services/main.js +3 -8
- package/build/src/debug.d.ts +1 -1
- package/build/src/types.js +1 -1
- package/package.json +35 -29
- package/build/chunk-ADS4GRIL.js +0 -14
|
@@ -1,87 +1,64 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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
|
-
|
|
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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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
|
-
|
|
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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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.js
CHANGED
|
@@ -1,231 +1,151 @@
|
|
|
1
|
-
import "
|
|
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
|
-
|
|
6
|
+
return new Store(options);
|
|
11
7
|
}
|
|
12
8
|
var Store = class {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
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
|
-
|
|
82
|
+
return config;
|
|
115
83
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
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
|
-
|
|
223
|
-
// index.ts
|
|
224
|
-
import { tracingChannels } from "bentocache";
|
|
225
|
-
export {
|
|
226
|
-
configure,
|
|
227
|
-
defineConfig,
|
|
228
|
-
drivers,
|
|
229
|
-
store,
|
|
230
|
-
tracingChannels
|
|
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
|
+
}
|
|
231
150
|
};
|
|
151
|
+
export { configure, defineConfig, drivers, store, tracingChannels };
|
|
@@ -1,97 +1,57 @@
|
|
|
1
|
-
import "
|
|
2
|
-
|
|
3
|
-
// src/bindings/repl.ts
|
|
1
|
+
import { debuglog } from "node:util";
|
|
4
2
|
function setupReplState(repl, key, value) {
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
|
|
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
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Register bindings
|
|
73
|
-
*/
|
|
74
|
-
register() {
|
|
75
|
-
this.#registerCacheManager();
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Boot provider
|
|
79
|
-
*/
|
|
80
|
-
async boot() {
|
|
81
|
-
await this.#registerEdgeBindings();
|
|
82
|
-
await this.#registerReplBindings();
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Gracefully shutdown connections when app goes down
|
|
86
|
-
*/
|
|
87
|
-
async shutdown() {
|
|
88
|
-
try {
|
|
89
|
-
const cache = await this.app.container.make("cache.manager");
|
|
90
|
-
await cache.disconnectAll();
|
|
91
|
-
} catch (_e) {
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
export {
|
|
96
|
-
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
|
+
}
|
|
97
56
|
};
|
|
57
|
+
export { CacheProvider as default };
|
package/build/services/main.js
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
|
-
import "../chunk-ADS4GRIL.js";
|
|
2
|
-
|
|
3
|
-
// services/main.ts
|
|
4
1
|
import app from "@adonisjs/core/services/app";
|
|
5
|
-
|
|
2
|
+
let cache;
|
|
6
3
|
await app.booted(async () => {
|
|
7
|
-
|
|
4
|
+
cache = await app.container.make("cache.manager");
|
|
8
5
|
});
|
|
9
|
-
export {
|
|
10
|
-
cache as default
|
|
11
|
-
};
|
|
6
|
+
export { cache as default };
|
package/build/src/debug.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: import("util").DebugLogger;
|
|
1
|
+
declare const _default: import("node:util").DebugLogger;
|
|
2
2
|
export default _default;
|
package/build/src/types.js
CHANGED
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
|
|
4
|
+
"version": "2.0.1",
|
|
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": "
|
|
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
|
|
42
|
-
"@adonisjs/core": "^7.0.0
|
|
43
|
-
"@adonisjs/eslint-config": "^3.0.0
|
|
44
|
-
"@adonisjs/lucid": "^22.0.0
|
|
41
|
+
"@adonisjs/assembler": "^8.0.0",
|
|
42
|
+
"@adonisjs/core": "^7.0.0",
|
|
43
|
+
"@adonisjs/eslint-config": "^3.0.0",
|
|
44
|
+
"@adonisjs/lucid": "^22.0.0",
|
|
45
45
|
"@adonisjs/prettier-config": "^1.4.5",
|
|
46
|
-
"@adonisjs/redis": "^10.0.0
|
|
47
|
-
"@adonisjs/tsconfig": "^2.0.0
|
|
46
|
+
"@adonisjs/redis": "^10.0.0",
|
|
47
|
+
"@adonisjs/tsconfig": "^2.0.0",
|
|
48
48
|
"@japa/assert": "^4.2.0",
|
|
49
49
|
"@japa/expect-type": "^2.0.4",
|
|
50
|
-
"@japa/file-system": "^
|
|
51
|
-
"@japa/runner": "^
|
|
50
|
+
"@japa/file-system": "^3.0.0",
|
|
51
|
+
"@japa/runner": "^5.3.0",
|
|
52
52
|
"@japa/snapshot": "^2.0.10",
|
|
53
|
-
"@poppinss/ts-exec": "^1.4.
|
|
54
|
-
"@release-it/conventional-changelog": "^10.0.
|
|
55
|
-
"@types/node": "~
|
|
56
|
-
"better-sqlite3": "^12.
|
|
57
|
-
"c8": "^
|
|
53
|
+
"@poppinss/ts-exec": "^1.4.4",
|
|
54
|
+
"@release-it/conventional-changelog": "^10.0.5",
|
|
55
|
+
"@types/node": "~25.3.0",
|
|
56
|
+
"better-sqlite3": "^12.6.2",
|
|
57
|
+
"c8": "^11.0.0",
|
|
58
58
|
"copyfiles": "^2.4.1",
|
|
59
59
|
"del-cli": "^7.0.0",
|
|
60
|
-
"edge.js": "^6.
|
|
61
|
-
"eslint": "^9.39.
|
|
62
|
-
"ioredis": "^5.
|
|
60
|
+
"edge.js": "^6.5.0",
|
|
61
|
+
"eslint": "^9.39.3",
|
|
62
|
+
"ioredis": "^5.9.3",
|
|
63
63
|
"knex": "^3.1.0",
|
|
64
64
|
"luxon": "^3.7.2",
|
|
65
|
-
"mysql2": "^3.
|
|
66
|
-
"p-event": "^7.0
|
|
67
|
-
"pg": "^8.
|
|
68
|
-
"prettier": "^3.
|
|
69
|
-
"release-it": "^19.2.
|
|
70
|
-
"
|
|
65
|
+
"mysql2": "^3.18.1",
|
|
66
|
+
"p-event": "^7.1.0",
|
|
67
|
+
"pg": "^8.19.0",
|
|
68
|
+
"prettier": "^3.8.1",
|
|
69
|
+
"release-it": "^19.2.4",
|
|
70
|
+
"tsdown": "^0.20.3",
|
|
71
71
|
"typescript": "~5.9.3"
|
|
72
72
|
},
|
|
73
73
|
"dependencies": {
|
|
74
|
-
"bentocache": "^1.6.
|
|
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
|
-
"
|
|
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
|
-
"
|
|
162
|
-
"
|
|
163
|
+
"treeshake": false,
|
|
164
|
+
"sourcemaps": false,
|
|
165
|
+
"target": "esnext",
|
|
166
|
+
"external": [
|
|
167
|
+
"edge.js"
|
|
168
|
+
]
|
|
163
169
|
},
|
|
164
|
-
"packageManager": "pnpm@10.
|
|
170
|
+
"packageManager": "pnpm@10.30.2"
|
|
165
171
|
}
|
package/build/chunk-ADS4GRIL.js
DELETED
|
@@ -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
|
-
};
|