@spoosh/plugin-gc 0.1.4 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +8 -2
- package/dist/index.mjs +8 -2
- package/package.json +7 -7
package/dist/index.d.mts
CHANGED
|
@@ -31,7 +31,7 @@ type GcPluginExports = {
|
|
|
31
31
|
*
|
|
32
32
|
* @param options - Plugin options
|
|
33
33
|
*
|
|
34
|
-
* @see {@link https://spoosh.dev/docs/plugins/gc | GC Plugin Documentation}
|
|
34
|
+
* @see {@link https://spoosh.dev/docs/react/plugins/gc | GC Plugin Documentation}
|
|
35
35
|
*
|
|
36
36
|
* @example
|
|
37
37
|
* ```ts
|
package/dist/index.d.ts
CHANGED
|
@@ -31,7 +31,7 @@ type GcPluginExports = {
|
|
|
31
31
|
*
|
|
32
32
|
* @param options - Plugin options
|
|
33
33
|
*
|
|
34
|
-
* @see {@link https://spoosh.dev/docs/plugins/gc | GC Plugin Documentation}
|
|
34
|
+
* @see {@link https://spoosh.dev/docs/react/plugins/gc | GC Plugin Documentation}
|
|
35
35
|
*
|
|
36
36
|
* @example
|
|
37
37
|
* ```ts
|
package/dist/index.js
CHANGED
|
@@ -32,6 +32,9 @@ function runGarbageCollection(stateManager, options) {
|
|
|
32
32
|
const entries = stateManager.getAllCacheEntries();
|
|
33
33
|
if (maxAge !== void 0) {
|
|
34
34
|
for (const { key, entry } of entries) {
|
|
35
|
+
if (stateManager.getSubscribersCount(key) > 0) {
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
35
38
|
const age = now - entry.state.timestamp;
|
|
36
39
|
if (age > maxAge) {
|
|
37
40
|
stateManager.deleteCache(key);
|
|
@@ -41,12 +44,15 @@ function runGarbageCollection(stateManager, options) {
|
|
|
41
44
|
}
|
|
42
45
|
if (maxEntries !== void 0) {
|
|
43
46
|
const currentEntries = stateManager.getAllCacheEntries();
|
|
47
|
+
const gcCandidates = currentEntries.filter(
|
|
48
|
+
({ key }) => stateManager.getSubscribersCount(key) === 0
|
|
49
|
+
);
|
|
44
50
|
const excess = currentEntries.length - maxEntries;
|
|
45
51
|
if (excess > 0) {
|
|
46
|
-
const sorted =
|
|
52
|
+
const sorted = gcCandidates.sort(
|
|
47
53
|
(a, b) => a.entry.state.timestamp - b.entry.state.timestamp
|
|
48
54
|
);
|
|
49
|
-
for (let i = 0; i < excess; i++) {
|
|
55
|
+
for (let i = 0; i < Math.min(excess, sorted.length); i++) {
|
|
50
56
|
const entry = sorted[i];
|
|
51
57
|
if (entry) {
|
|
52
58
|
stateManager.deleteCache(entry.key);
|
package/dist/index.mjs
CHANGED
|
@@ -6,6 +6,9 @@ function runGarbageCollection(stateManager, options) {
|
|
|
6
6
|
const entries = stateManager.getAllCacheEntries();
|
|
7
7
|
if (maxAge !== void 0) {
|
|
8
8
|
for (const { key, entry } of entries) {
|
|
9
|
+
if (stateManager.getSubscribersCount(key) > 0) {
|
|
10
|
+
continue;
|
|
11
|
+
}
|
|
9
12
|
const age = now - entry.state.timestamp;
|
|
10
13
|
if (age > maxAge) {
|
|
11
14
|
stateManager.deleteCache(key);
|
|
@@ -15,12 +18,15 @@ function runGarbageCollection(stateManager, options) {
|
|
|
15
18
|
}
|
|
16
19
|
if (maxEntries !== void 0) {
|
|
17
20
|
const currentEntries = stateManager.getAllCacheEntries();
|
|
21
|
+
const gcCandidates = currentEntries.filter(
|
|
22
|
+
({ key }) => stateManager.getSubscribersCount(key) === 0
|
|
23
|
+
);
|
|
18
24
|
const excess = currentEntries.length - maxEntries;
|
|
19
25
|
if (excess > 0) {
|
|
20
|
-
const sorted =
|
|
26
|
+
const sorted = gcCandidates.sort(
|
|
21
27
|
(a, b) => a.entry.state.timestamp - b.entry.state.timestamp
|
|
22
28
|
);
|
|
23
|
-
for (let i = 0; i < excess; i++) {
|
|
29
|
+
for (let i = 0; i < Math.min(excess, sorted.length); i++) {
|
|
24
30
|
const entry = sorted[i];
|
|
25
31
|
if (entry) {
|
|
26
32
|
stateManager.deleteCache(entry.key);
|
package/package.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spoosh/plugin-gc",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"description": "Garbage collection plugin for Spoosh cache with time and size-based cleanup",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
|
-
"url": "git+https://github.com/
|
|
8
|
+
"url": "git+https://github.com/spooshdev/spoosh.git",
|
|
9
9
|
"directory": "packages/plugin-gc"
|
|
10
10
|
},
|
|
11
11
|
"bugs": {
|
|
12
|
-
"url": "https://github.com/
|
|
12
|
+
"url": "https://github.com/spooshdev/spoosh/issues"
|
|
13
13
|
},
|
|
14
|
-
"homepage": "https://spoosh.dev/react/
|
|
14
|
+
"homepage": "https://spoosh.dev/docs/react/plugins/gc",
|
|
15
15
|
"publishConfig": {
|
|
16
16
|
"access": "public"
|
|
17
17
|
},
|
|
@@ -34,11 +34,11 @@
|
|
|
34
34
|
}
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
|
-
"@spoosh/core": ">=0.
|
|
37
|
+
"@spoosh/core": ">=0.10.2"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@spoosh/core": "0.
|
|
41
|
-
"@spoosh/test-utils": "0.1.
|
|
40
|
+
"@spoosh/core": "0.11.0",
|
|
41
|
+
"@spoosh/test-utils": "0.1.6"
|
|
42
42
|
},
|
|
43
43
|
"scripts": {
|
|
44
44
|
"dev": "tsup --watch",
|