@roots/bud-cache 6.9.0 → 6.10.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/README.md CHANGED
@@ -60,7 +60,9 @@ Keep track of development and community news.
60
60
 
61
61
  ## Sponsors
62
62
 
63
- Help support our open-source development efforts by [becoming a patron](https://www.patreon.com/rootsdev).
63
+ **Bud** is an open source project and completely free to use.
64
+
65
+ However, the amount of effort needed to maintain and develop new features and projects within the Roots ecosystem is not sustainable without proper financial backing. If you have the capability, please consider [sponsoring Roots](https://github.com/sponsors/roots).
64
66
 
65
67
  <a href="https://k-m.com/">
66
68
  <img src="https://cdn.roots.io/app/uploads/km-digital.svg" alt="KM Digital" width="200" height="150"/>
@@ -77,3 +79,6 @@ Help support our open-source development efforts by [becoming a patron](https://
77
79
  <a href="https://worksitesafety.ca/careers/">
78
80
  <img src="https://cdn.roots.io/app/uploads/worksite-safety.svg" alt="Worksite Safety" width="200" height="150"/>
79
81
  </a>
82
+ <a href="https://www.copiadigital.com/">
83
+ <img src="https://cdn.roots.io/app/uploads/copia-digital.svg" alt="Copia Digital" width="200" height="150"/>
84
+ </a>
@@ -0,0 +1,8 @@
1
+ ---
2
+ title: Exports
3
+ ---
4
+
5
+ | Signifier | Description |
6
+ | :-------------------------------------------- | :---------------------------------------------------- |
7
+ | `@roots/bud-cache` | The `bud.cache` service |
8
+ | `@roots/bud-cache/invalidate-cache-extension` | Extension which invalidates cache during build errors |
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@roots/bud-cache",
3
3
  "description": "Config caching",
4
- "version": "6.9.0",
4
+ "version": "6.10.0",
5
5
  "homepage": "https://roots.io/bud",
6
6
  "repository": {
7
7
  "type": "git",
@@ -40,15 +40,28 @@
40
40
  "node": ">=16"
41
41
  },
42
42
  "files": [
43
- "lib/",
44
- "types/"
43
+ "docs",
44
+ "lib",
45
+ "src"
45
46
  ],
46
47
  "type": "module",
47
- "module": "./lib/index.js",
48
- "types": "./lib/index.d.ts",
49
48
  "exports": {
50
- ".": "./lib/index.js",
51
- "./service": "./lib/service.js"
49
+ ".": {
50
+ "types": "./lib/index.d.ts",
51
+ "import": "./lib/index.js"
52
+ },
53
+ "./service": {
54
+ "types": "./lib/service/index.js",
55
+ "import": "./lib/service.js"
56
+ },
57
+ "./invalidate-cache": {
58
+ "types": "./lib/invalidate-cache/index.d.ts",
59
+ "import": "./lib/invalidate-cache/index.js"
60
+ },
61
+ "./types": {
62
+ "types": "./lib/types.d.ts",
63
+ "import": "./lib/types.js"
64
+ }
52
65
  },
53
66
  "typesVersions": {
54
67
  "*": {
@@ -57,15 +70,20 @@
57
70
  ],
58
71
  "./service": [
59
72
  "./lib/service.d.ts"
73
+ ],
74
+ "./types": [
75
+ "./lib/types.d.ts"
60
76
  ]
61
77
  }
62
78
  },
79
+ "module": "./lib/index.js",
80
+ "types": "./lib/index.d.ts",
63
81
  "devDependencies": {
64
82
  "@skypack/package-check": "0.2.2"
65
83
  },
66
84
  "dependencies": {
67
- "@roots/bud-framework": "6.9.0",
68
- "@roots/bud-support": "6.9.0",
85
+ "@roots/bud-framework": "6.10.0",
86
+ "@roots/bud-support": "6.10.0",
69
87
  "strip-ansi": "7.0.1"
70
88
  },
71
89
  "volta": {
package/src/index.ts ADDED
@@ -0,0 +1,17 @@
1
+ // Copyright © Roots Software Foundation LLC
2
+ // Licensed under the MIT license.
3
+
4
+ /**
5
+ * Caching service
6
+ *
7
+ * @see {@link https://bud.js.org}
8
+ * @see {@link https://github.com/roots/bud}
9
+ *
10
+ * @packageDocumentation
11
+ */
12
+
13
+ import './types.js'
14
+
15
+ import Cache from './service/index.js'
16
+
17
+ export default Cache
@@ -0,0 +1,56 @@
1
+ import {join} from 'node:path'
2
+
3
+ import type {Bud} from '@roots/bud-framework'
4
+ import {Extension} from '@roots/bud-framework/extension'
5
+ import {bind, label} from '@roots/bud-framework/extension/decorators'
6
+ import stripAnsi from 'strip-ansi'
7
+
8
+ /**
9
+ * Cache invalidation extension
10
+ *
11
+ * @remarks
12
+ * Certain webpack components such as `eslint-webpack-plugin` and
13
+ * `ts-loader` have issues with fs caching. This extension writes a file
14
+ * to the cache directory which is used to invalidate the cache before
15
+ * webpack is invoked on subsequent builds
16
+ */
17
+ @label(`@roots/bud-cache/invalidate-cache`)
18
+ export default class InvalidateCacheExtension extends Extension {
19
+ /**
20
+ * Invalidation file path
21
+ */
22
+ public get invalidationFile(): string {
23
+ return join(this.app.cache.cacheDirectory, `error.json`)
24
+ }
25
+
26
+ /**
27
+ * `register` callback
28
+ */
29
+ @bind
30
+ public override async register(bud: Bud) {
31
+ const invalidate = await bud.fs?.exists(this.invalidationFile)
32
+
33
+ if (invalidate || (bud.isCLI() && bud.context.args.flush)) {
34
+ await bud.fs.remove(this.invalidationFile)
35
+ await bud.fs.remove(bud.cache.cacheDirectory)
36
+ }
37
+
38
+ bud.after(async () => {
39
+ bud.compiler.instance.hooks.done.tap(this.label, async compiler => {
40
+ try {
41
+ if (!compiler.hasErrors()) return
42
+
43
+ await bud.fs.json.write(this.invalidationFile, {
44
+ hash: compiler.hash,
45
+ errors: compiler.stats.flatMap(stats =>
46
+ stats
47
+ .toString({preset: `errors-warnings`, colors: false})
48
+ .split(/\n/)
49
+ .map(stripAnsi),
50
+ ),
51
+ })
52
+ } catch (e) {}
53
+ })
54
+ })
55
+ }
56
+ }
@@ -0,0 +1,125 @@
1
+ import {createHash} from 'node:crypto'
2
+
3
+ import type {Bud} from '@roots/bud-framework'
4
+ import {Service} from '@roots/bud-framework/service'
5
+ import type * as Services from '@roots/bud-framework/services'
6
+ import {bind} from '@roots/bud-support/decorators'
7
+ import isString from '@roots/bud-support/lodash/isString'
8
+ import join from '@roots/bud-support/lodash/join'
9
+ import type {Configuration} from '@roots/bud-support/webpack'
10
+
11
+ import InvalidateCacheExtension from '../invalidate-cache/index.js'
12
+
13
+ /**
14
+ * Cache service class
15
+ */
16
+ export default class Cache
17
+ extends Service
18
+ implements Services.Cache.Service
19
+ {
20
+ /**
21
+ * Enabled
22
+ */
23
+ public enabled: boolean = true
24
+
25
+ /**
26
+ * Type
27
+ */
28
+ public get name(): string {
29
+ return this.app.hooks.filter(
30
+ `build.cache.name`,
31
+ this.app.hooks.filter(`build.name`, this.app.context.label),
32
+ )
33
+ }
34
+ public set name(name: string) {
35
+ this.app.hooks.on(`build.cache.name`, name)
36
+ }
37
+
38
+ /**
39
+ * Type
40
+ */
41
+ public get type(): 'memory' | 'filesystem' {
42
+ return this.app.hooks.filter(
43
+ `build.cache.type`,
44
+ this.app.isCLI() && isString(this.app.context.args.cache)
45
+ ? this.app.context.args.cache
46
+ : `filesystem`,
47
+ )
48
+ }
49
+
50
+ public set type(type: 'memory' | 'filesystem') {
51
+ this.app.hooks.on(`build.cache.type`, type)
52
+ }
53
+
54
+ /**
55
+ * version
56
+ */
57
+ public get version(): string {
58
+ const args = this.app.fs.json.stringify(
59
+ this.app.isCLI() ? this.app.context.args : {},
60
+ )
61
+ const files = Object.values(this.app.context.config ?? {}).filter(
62
+ file => file?.bud && file.sha1,
63
+ )
64
+
65
+ return this.app.hooks.filter(
66
+ `build.cache.version`,
67
+ createHash(`sha1`)
68
+ .update(join(args, ...files.map(({module: {sha1}}) => sha1)))
69
+ .digest(`base64`),
70
+ )
71
+ }
72
+ public set version(version: string) {
73
+ this.app.hooks.on(`build.cache.version`, version)
74
+ }
75
+
76
+ /**
77
+ * Cache directory
78
+ */
79
+ public get cacheDirectory(): string {
80
+ return this.app.hooks.filter(
81
+ `build.cache.cacheDirectory`,
82
+ this.app.path(`@storage`, this.app.label, `cache`, this.app.mode),
83
+ )
84
+ }
85
+ public set cacheDirectory(directory: string) {
86
+ this.app.hooks.on(`build.cache.cacheDirectory`, directory)
87
+ }
88
+
89
+ /**
90
+ * Webpack configuration
91
+ */
92
+ public get configuration(): Configuration[`cache`] {
93
+ if (this.enabled !== true) return false
94
+ return this.type === `memory`
95
+ ? true
96
+ : {
97
+ name: this.name,
98
+ type: this.type,
99
+ store: `pack` as `pack`,
100
+ allowCollectingMemory: true,
101
+ cacheDirectory: this.cacheDirectory,
102
+ idleTimeout: 10000,
103
+ idleTimeoutForInitialStore: 0,
104
+ profile: true,
105
+ version: this.version,
106
+ }
107
+ }
108
+
109
+ /**
110
+ * {@link Extension.booted}
111
+ */
112
+ @bind
113
+ public override async booted?(bud: Bud) {
114
+ await bud.extensions.add(InvalidateCacheExtension)
115
+ this.app.success(`cache initialized`)
116
+ }
117
+
118
+ /**
119
+ * Flush cache
120
+ */
121
+ @bind
122
+ public async flush(): Promise<void> {
123
+ await this.app.fs.remove(this.cacheDirectory)
124
+ }
125
+ }
package/src/types.ts ADDED
@@ -0,0 +1,7 @@
1
+ import type InvalidateCacheExtension from './invalidate-cache/index.js'
2
+
3
+ declare module '@roots/bud-framework' {
4
+ interface Modules {
5
+ '@roots/bud-cache/invalidate-cache': InvalidateCacheExtension
6
+ }
7
+ }
package/lib/index.d.ts DELETED
@@ -1,17 +0,0 @@
1
- /**
2
- * Compiler and pre-compiler caching
3
- *
4
- * @see {@link https://bud.js.org}
5
- * @see {@link https://github.com/roots/bud}
6
- *
7
- * @packageDocumentation
8
- */
9
- import type InvalidateCacheExtension from './invalidate-cache-extension/index.js';
10
- import Cache from './service.js';
11
- declare module '@roots/bud-framework' {
12
- interface Modules {
13
- '@roots/bud-cache/invalidate-cache': InvalidateCacheExtension;
14
- }
15
- }
16
- export default Cache;
17
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA;;;;;;;GAOG;AAEH,OAAO,KAAK,wBAAwB,MAAM,uCAAuC,CAAA;AACjF,OAAO,KAAK,MAAM,cAAc,CAAA;AAEhC,OAAO,QAAQ,sBAAsB,CAAC;IACpC,UAAU,OAAO;QACf,mCAAmC,EAAE,wBAAwB,CAAA;KAC9D;CACF;AAED,eAAe,KAAK,CAAA"}
package/lib/index.js DELETED
@@ -1,5 +0,0 @@
1
- // Copyright © Roots Software Foundation LLC
2
- // Licensed under the MIT license.
3
- import Cache from './service.js';
4
- export default Cache;
5
- //# sourceMappingURL=index.js.map
package/lib/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,kCAAkC;AAYlC,OAAO,KAAK,MAAM,cAAc,CAAA;AAQhC,eAAe,KAAK,CAAA"}
@@ -1,29 +0,0 @@
1
- import type { Bud } from '@roots/bud-framework';
2
- import { Extension } from '@roots/bud-framework/extension';
3
- /**
4
- * Cache invalidation extension
5
- *
6
- * @remarks
7
- * Certain webpack components such as `eslint-webpack-plugin` and
8
- * `ts-loader` have issues with fs caching. This extension writes a file
9
- * to the cache directory which is used to invalidate the cache before
10
- * webpack is invoked on subsequent builds
11
- *
12
- * @public
13
- * @decorator `@label`
14
- */
15
- export default class InvalidateCacheExtension extends Extension {
16
- /**
17
- * Invalidation file path
18
- * @public
19
- */
20
- get invalidationFile(): string;
21
- /**
22
- * `register` callback
23
- *
24
- * @public
25
- * @decorator `@bind`
26
- */
27
- register(bud: Bud): Promise<void>;
28
- }
29
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/invalidate-cache-extension/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAC,GAAG,EAAC,MAAM,sBAAsB,CAAA;AAC7C,OAAO,EAAC,SAAS,EAAC,MAAM,gCAAgC,CAAA;AAIxD;;;;;;;;;;;GAWG;AAEH,MAAM,CAAC,OAAO,OAAO,wBAAyB,SAAQ,SAAS;IAC7D;;;OAGG;IACH,IAAW,gBAAgB,IAAI,MAAM,CAEpC;IAED;;;;;OAKG;IAEmB,QAAQ,CAAC,GAAG,EAAE,GAAG;CA0BxC"}
@@ -1,66 +0,0 @@
1
- import { __decorate, __metadata } from "tslib";
2
- import { join } from 'node:path';
3
- import { Extension } from '@roots/bud-framework/extension';
4
- import { bind, label } from '@roots/bud-framework/extension/decorators';
5
- import stripAnsi from 'strip-ansi';
6
- /**
7
- * Cache invalidation extension
8
- *
9
- * @remarks
10
- * Certain webpack components such as `eslint-webpack-plugin` and
11
- * `ts-loader` have issues with fs caching. This extension writes a file
12
- * to the cache directory which is used to invalidate the cache before
13
- * webpack is invoked on subsequent builds
14
- *
15
- * @public
16
- * @decorator `@label`
17
- */
18
- let InvalidateCacheExtension = class InvalidateCacheExtension extends Extension {
19
- /**
20
- * Invalidation file path
21
- * @public
22
- */
23
- get invalidationFile() {
24
- return join(this.app.cache.cacheDirectory, `error.json`);
25
- }
26
- /**
27
- * `register` callback
28
- *
29
- * @public
30
- * @decorator `@bind`
31
- */
32
- async register(bud) {
33
- const invalidate = await bud.fs?.exists(this.invalidationFile);
34
- if (invalidate || (bud.isCLI() && bud.context.args.flush)) {
35
- await bud.fs.remove(this.invalidationFile);
36
- await bud.fs.remove(bud.cache.cacheDirectory);
37
- }
38
- bud.after(async () => {
39
- bud.compiler.instance.hooks.done.tap(this.label, async (compiler) => {
40
- try {
41
- if (!compiler.hasErrors())
42
- return;
43
- await bud.fs.json.write(this.invalidationFile, {
44
- hash: compiler.hash,
45
- errors: compiler.stats.flatMap(stats => stats
46
- .toString({ preset: `errors-warnings`, colors: false })
47
- .split(/\n/)
48
- .map(stripAnsi)),
49
- });
50
- }
51
- catch (e) { }
52
- });
53
- });
54
- }
55
- };
56
- __decorate([
57
- bind,
58
- __metadata("design:type", Function),
59
- __metadata("design:paramtypes", [Function]),
60
- __metadata("design:returntype", Promise)
61
- ], InvalidateCacheExtension.prototype, "register", null);
62
- InvalidateCacheExtension = __decorate([
63
- label(`@roots/bud-cache/invalidate-cache`)
64
- ], InvalidateCacheExtension);
65
- export default InvalidateCacheExtension;
66
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/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gBAAgB,EAAE;wBAC7C,IAAI,EAAE,QAAQ,CAAC,IAAI;wBACnB,MAAM,EAAE,QAAQ,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CACrC,KAAK;6BACF,QAAQ,CAAC,EAAC,MAAM,EAAE,iBAAiB,EAAE,MAAM,EAAE,KAAK,EAAC,CAAC;6BACpD,KAAK,CAAC,IAAI,CAAC;6BACX,GAAG,CAAC,SAAS,CAAC,CAClB;qBACF,CAAC,CAAA;iBACH;gBAAC,OAAO,CAAC,EAAE,GAAE;YAChB,CAAC,CAAC,CAAA;QACJ,CAAC,CAAC,CAAA;IACJ,CAAC;CACF,CAAA;AA1BuB;IADrB,IAAI;;;;wDA0BJ;AAzCkB,wBAAwB;IAD5C,KAAK,CAAC,mCAAmC,CAAC;GACtB,wBAAwB,CA0C5C;eA1CoB,wBAAwB"}
package/lib/service.d.ts DELETED
@@ -1,60 +0,0 @@
1
- import { Service } from '@roots/bud-framework/service';
2
- import type * as Services from '@roots/bud-framework/services';
3
- import type { Configuration } from '@roots/bud-support/webpack';
4
- /**
5
- * Cache service class
6
- */
7
- export default class Cache extends Service implements Services.Cache.Service {
8
- /**
9
- * Enabled
10
- *
11
- * @public
12
- */
13
- enabled: boolean;
14
- /**
15
- * Type
16
- *
17
- * @public
18
- */
19
- get name(): string;
20
- set name(name: string);
21
- /**
22
- * Type
23
- *
24
- * @public
25
- */
26
- get type(): 'memory' | 'filesystem';
27
- set type(type: 'memory' | 'filesystem');
28
- /**
29
- * version
30
- *
31
- * @public
32
- */
33
- get version(): string;
34
- set version(version: string);
35
- /**
36
- * Cache directory
37
- *
38
- * @public
39
- */
40
- get cacheDirectory(): string;
41
- set cacheDirectory(directory: string);
42
- /**
43
- * Webpack configuration
44
- *
45
- * @public
46
- */
47
- get configuration(): Configuration[`cache`];
48
- /**
49
- * `booted` callback
50
- *
51
- * @public
52
- * @decorator `@bind`
53
- */
54
- booted?(): Promise<void>;
55
- /**
56
- * Flush cache
57
- */
58
- flush(): Promise<void>;
59
- }
60
- //# sourceMappingURL=service.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,OAAO,EAAC,MAAM,8BAA8B,CAAA;AACpD,OAAO,KAAK,KAAK,QAAQ,MAAM,+BAA+B,CAAA;AAI9D,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,4BAA4B,CAAA;AAI7D;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,KACnB,SAAQ,OACR,YAAW,QAAQ,CAAC,KAAK,CAAC,OAAO;IAEjC;;;;OAIG;IACI,OAAO,EAAE,OAAO,CAAO;IAE9B;;;;OAIG;IACH,IAAW,IAAI,IAAI,MAAM,CAKxB;IACD,IAAW,IAAI,CAAC,IAAI,EAAE,MAAM,EAE3B;IAED;;;;OAIG;IACH,IAAW,IAAI,IAAI,QAAQ,GAAG,YAAY,CAOzC;IAED,IAAW,IAAI,CAAC,IAAI,EAAE,QAAQ,GAAG,YAAY,EAE5C;IAED;;;;OAIG;IACH,IAAW,OAAO,IAAI,MAAM,CAc3B;IACD,IAAW,OAAO,CAAC,OAAO,EAAE,MAAM,EAEjC;IAED;;;;OAIG;IACH,IAAW,cAAc,IAAI,MAAM,CAKlC;IACD,IAAW,cAAc,CAAC,SAAS,EAAE,MAAM,EAE1C;IAED;;;;OAIG;IACH,IAAW,aAAa,IAAI,aAAa,CAAC,OAAO,CAAC,CAejD;IAED;;;;;OAKG;IAEmB,MAAM,CAAC;IAK7B;;OAEG;IAEU,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAGpC"}
package/lib/service.js DELETED
@@ -1,122 +0,0 @@
1
- import { __decorate, __metadata } from "tslib";
2
- import { createHash } from 'node:crypto';
3
- import { Service } from '@roots/bud-framework/service';
4
- import { bind } from '@roots/bud-support/decorators';
5
- import isString from '@roots/bud-support/lodash/isString';
6
- import join from '@roots/bud-support/lodash/join';
7
- import InvalidateCacheExtension from './invalidate-cache-extension/index.js';
8
- /**
9
- * Cache service class
10
- */
11
- export default class Cache extends Service {
12
- constructor() {
13
- super(...arguments);
14
- /**
15
- * Enabled
16
- *
17
- * @public
18
- */
19
- this.enabled = true;
20
- }
21
- /**
22
- * Type
23
- *
24
- * @public
25
- */
26
- get name() {
27
- return this.app.hooks.filter(`build.cache.name`, this.app.hooks.filter(`build.name`, this.app.context.label));
28
- }
29
- set name(name) {
30
- this.app.hooks.on(`build.cache.name`, name);
31
- }
32
- /**
33
- * Type
34
- *
35
- * @public
36
- */
37
- get type() {
38
- return this.app.hooks.filter(`build.cache.type`, this.app.isCLI() && isString(this.app.context.args.cache)
39
- ? this.app.context.args.cache
40
- : `filesystem`);
41
- }
42
- set type(type) {
43
- this.app.hooks.on(`build.cache.type`, type);
44
- }
45
- /**
46
- * version
47
- *
48
- * @public
49
- */
50
- get version() {
51
- const args = this.app.fs.json.stringify(this.app.isCLI() ? this.app.context.args : {});
52
- const files = Object.values(this.app.context.config ?? {}).filter(file => file?.bud && file.sha1);
53
- return this.app.hooks.filter(`build.cache.version`, createHash(`sha1`)
54
- .update(join(args, ...files.map(({ module: { sha1 } }) => sha1)))
55
- .digest(`base64`));
56
- }
57
- set version(version) {
58
- this.app.hooks.on(`build.cache.version`, version);
59
- }
60
- /**
61
- * Cache directory
62
- *
63
- * @public
64
- */
65
- get cacheDirectory() {
66
- return this.app.hooks.filter(`build.cache.cacheDirectory`, this.app.path(`@storage`, this.app.label, `cache`, this.app.mode));
67
- }
68
- set cacheDirectory(directory) {
69
- this.app.hooks.on(`build.cache.cacheDirectory`, directory);
70
- }
71
- /**
72
- * Webpack configuration
73
- *
74
- * @public
75
- */
76
- get configuration() {
77
- if (this.enabled !== true)
78
- return false;
79
- return this.type === `memory`
80
- ? true
81
- : {
82
- name: this.name,
83
- type: this.type,
84
- store: `pack`,
85
- allowCollectingMemory: true,
86
- cacheDirectory: this.cacheDirectory,
87
- idleTimeout: 10000,
88
- idleTimeoutForInitialStore: 0,
89
- profile: true,
90
- version: this.version,
91
- };
92
- }
93
- /**
94
- * `booted` callback
95
- *
96
- * @public
97
- * @decorator `@bind`
98
- */
99
- async booted() {
100
- await this.app.extensions.add(InvalidateCacheExtension);
101
- this.app.success(`cache initialized`);
102
- }
103
- /**
104
- * Flush cache
105
- */
106
- async flush() {
107
- await this.app.fs.remove(this.cacheDirectory);
108
- }
109
- }
110
- __decorate([
111
- bind,
112
- __metadata("design:type", Function),
113
- __metadata("design:paramtypes", []),
114
- __metadata("design:returntype", Promise)
115
- ], Cache.prototype, "booted", null);
116
- __decorate([
117
- bind,
118
- __metadata("design:type", Function),
119
- __metadata("design:paramtypes", []),
120
- __metadata("design:returntype", Promise)
121
- ], Cache.prototype, "flush", null);
122
- //# sourceMappingURL=service.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"service.js","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,aAAa,CAAA;AAEtC,OAAO,EAAC,OAAO,EAAC,MAAM,8BAA8B,CAAA;AAEpD,OAAO,EAAC,IAAI,EAAC,MAAM,+BAA+B,CAAA;AAClD,OAAO,QAAQ,MAAM,oCAAoC,CAAA;AACzD,OAAO,IAAI,MAAM,gCAAgC,CAAA;AAGjD,OAAO,wBAAwB,MAAM,uCAAuC,CAAA;AAE5E;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,KACnB,SAAQ,OAAO;IADjB;;QAIE;;;;WAIG;QACI,YAAO,GAAY,IAAI,CAAA;IAmHhC,CAAC;IAjHC;;;;OAIG;IACH,IAAW,IAAI;QACb,OAAO,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,CAC1B,kBAAkB,EAClB,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,YAAY,EAAE,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,CAC5D,CAAA;IACH,CAAC;IACD,I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