mcp-wordpress 1.2.2 → 1.3.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 +210 -182
- package/dist/cache/CacheInvalidation.d.ts +3 -3
- package/dist/cache/CacheInvalidation.d.ts.map +1 -1
- package/dist/cache/CacheInvalidation.js +119 -119
- package/dist/cache/CacheInvalidation.js.map +1 -1
- package/dist/cache/CacheManager.d.ts +5 -0
- package/dist/cache/CacheManager.d.ts.map +1 -1
- package/dist/cache/CacheManager.js +26 -16
- package/dist/cache/CacheManager.js.map +1 -1
- package/dist/cache/HttpCacheWrapper.d.ts +1 -1
- package/dist/cache/HttpCacheWrapper.d.ts.map +1 -1
- package/dist/cache/HttpCacheWrapper.js +29 -29
- package/dist/cache/HttpCacheWrapper.js.map +1 -1
- package/dist/cache/__tests__/CacheInvalidation.test.js +96 -94
- package/dist/cache/__tests__/CacheInvalidation.test.js.map +1 -1
- package/dist/cache/__tests__/CacheManager.test.js +113 -113
- package/dist/cache/__tests__/CacheManager.test.js.map +1 -1
- package/dist/cache/__tests__/CachedWordPressClient.test.js +102 -99
- package/dist/cache/__tests__/CachedWordPressClient.test.js.map +1 -1
- package/dist/cache/__tests__/HttpCacheWrapper.test.js +98 -95
- package/dist/cache/__tests__/HttpCacheWrapper.test.js.map +1 -1
- package/dist/cache/index.d.ts +7 -7
- package/dist/cache/index.d.ts.map +1 -1
- package/dist/cache/index.js +4 -4
- package/dist/cache/index.js.map +1 -1
- package/dist/client/CachedWordPressClient.d.ts +4 -4
- package/dist/client/CachedWordPressClient.d.ts.map +1 -1
- package/dist/client/CachedWordPressClient.js +55 -51
- package/dist/client/CachedWordPressClient.js.map +1 -1
- package/dist/client/api.d.ts +10 -10
- package/dist/client/api.js +158 -158
- package/dist/client/api.js.map +1 -1
- package/dist/client/auth.d.ts +2 -2
- package/dist/client/auth.js +72 -72
- package/dist/client/managers/AuthenticationManager.d.ts +2 -2
- package/dist/client/managers/AuthenticationManager.js +46 -46
- package/dist/client/managers/BaseManager.d.ts +1 -1
- package/dist/client/managers/BaseManager.js +9 -9
- package/dist/client/managers/RequestManager.d.ts +5 -3
- package/dist/client/managers/RequestManager.d.ts.map +1 -1
- package/dist/client/managers/RequestManager.js +39 -19
- package/dist/client/managers/RequestManager.js.map +1 -1
- package/dist/client/managers/index.d.ts +3 -3
- package/dist/client/managers/index.js +3 -3
- package/dist/config/ConfigurationSchema.d.ts +2 -2
- package/dist/config/ConfigurationSchema.d.ts.map +1 -1
- package/dist/config/ConfigurationSchema.js +40 -40
- package/dist/config/ConfigurationSchema.js.map +1 -1
- package/dist/config/ServerConfiguration.d.ts +2 -2
- package/dist/config/ServerConfiguration.js +35 -35
- package/dist/config/ServerConfiguration.js.map +1 -1
- package/dist/docs/DocumentationGenerator.d.ts.map +1 -1
- package/dist/docs/DocumentationGenerator.js +296 -255
- package/dist/docs/DocumentationGenerator.js.map +1 -1
- package/dist/docs/MarkdownFormatter.d.ts +1 -1
- package/dist/docs/MarkdownFormatter.d.ts.map +1 -1
- package/dist/docs/MarkdownFormatter.js +60 -51
- package/dist/docs/MarkdownFormatter.js.map +1 -1
- package/dist/docs/index.d.ts +3 -3
- package/dist/docs/index.d.ts.map +1 -1
- package/dist/docs/index.js +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +16 -16
- package/dist/index.js.map +1 -1
- package/dist/mcp-wordpress-1.3.0.tgz +0 -0
- package/dist/performance/MetricsCollector.d.ts +3 -3
- package/dist/performance/MetricsCollector.d.ts.map +1 -1
- package/dist/performance/MetricsCollector.js +33 -27
- package/dist/performance/MetricsCollector.js.map +1 -1
- package/dist/performance/PerformanceAnalytics.d.ts +12 -12
- package/dist/performance/PerformanceAnalytics.d.ts.map +1 -1
- package/dist/performance/PerformanceAnalytics.js +200 -154
- package/dist/performance/PerformanceAnalytics.js.map +1 -1
- package/dist/performance/PerformanceMonitor.d.ts +5 -5
- package/dist/performance/PerformanceMonitor.d.ts.map +1 -1
- package/dist/performance/PerformanceMonitor.js +53 -52
- package/dist/performance/PerformanceMonitor.js.map +1 -1
- package/dist/performance/index.d.ts +6 -6
- package/dist/performance/index.d.ts.map +1 -1
- package/dist/performance/index.js +3 -3
- package/dist/security/InputValidator.d.ts +1 -1
- package/dist/security/InputValidator.d.ts.map +1 -1
- package/dist/security/InputValidator.js +111 -88
- package/dist/security/InputValidator.js.map +1 -1
- package/dist/security/SecurityConfig.d.ts +5 -5
- package/dist/security/SecurityConfig.js +92 -92
- package/dist/security/SecurityConfig.js.map +1 -1
- package/dist/server/ConnectionTester.d.ts +1 -1
- package/dist/server/ConnectionTester.d.ts.map +1 -1
- package/dist/server/ConnectionTester.js +4 -4
- package/dist/server/ConnectionTester.js.map +1 -1
- package/dist/server/ToolRegistry.d.ts +2 -2
- package/dist/server/ToolRegistry.d.ts.map +1 -1
- package/dist/server/ToolRegistry.js +35 -32
- package/dist/server/ToolRegistry.js.map +1 -1
- package/dist/server.d.ts +2 -2
- package/dist/server.js +2 -2
- package/dist/tools/BaseToolManager.js +5 -5
- package/dist/tools/auth.d.ts +2 -2
- package/dist/tools/auth.d.ts.map +1 -1
- package/dist/tools/auth.js +32 -31
- package/dist/tools/auth.js.map +1 -1
- package/dist/tools/cache.d.ts +1 -1
- package/dist/tools/cache.d.ts.map +1 -1
- package/dist/tools/cache.js +71 -71
- package/dist/tools/cache.js.map +1 -1
- package/dist/tools/comments.d.ts +2 -2
- package/dist/tools/comments.d.ts.map +1 -1
- package/dist/tools/comments.js +79 -79
- package/dist/tools/comments.js.map +1 -1
- package/dist/tools/index.d.ts +10 -10
- package/dist/tools/index.js +10 -10
- package/dist/tools/media.d.ts +2 -2
- package/dist/tools/media.js +80 -80
- package/dist/tools/pages.d.ts +2 -2
- package/dist/tools/pages.d.ts.map +1 -1
- package/dist/tools/pages.js +75 -75
- package/dist/tools/pages.js.map +1 -1
- package/dist/tools/performance.d.ts +1 -1
- package/dist/tools/performance.d.ts.map +1 -1
- package/dist/tools/performance.js +311 -287
- package/dist/tools/performance.js.map +1 -1
- package/dist/tools/posts.d.ts +2 -2
- package/dist/tools/posts.d.ts.map +1 -1
- package/dist/tools/posts.js +94 -94
- package/dist/tools/posts.js.map +1 -1
- package/dist/tools/site.d.ts +2 -2
- package/dist/tools/site.d.ts.map +1 -1
- package/dist/tools/site.js +60 -60
- package/dist/tools/site.js.map +1 -1
- package/dist/tools/taxonomies.d.ts +2 -2
- package/dist/tools/taxonomies.js +89 -89
- package/dist/tools/users.d.ts +2 -2
- package/dist/tools/users.js +68 -68
- package/dist/tools/users.js.map +1 -1
- package/dist/types/client.d.ts +13 -13
- package/dist/types/client.d.ts.map +1 -1
- package/dist/types/client.js +12 -12
- package/dist/types/client.js.map +1 -1
- package/dist/types/index.d.ts +19 -19
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +3 -3
- package/dist/types/mcp.d.ts +7 -7
- package/dist/types/wordpress.d.ts +21 -21
- package/dist/types/wordpress.d.ts.map +1 -1
- package/dist/utils/debug.d.ts +2 -2
- package/dist/utils/debug.js +28 -28
- package/dist/utils/error.d.ts.map +1 -1
- package/dist/utils/error.js +13 -13
- package/dist/utils/error.js.map +1 -1
- package/dist/utils/toolWrapper.d.ts.map +1 -1
- package/dist/utils/toolWrapper.js +5 -5
- package/dist/utils/toolWrapper.js.map +1 -1
- package/dist/utils/validation.d.ts.map +1 -1
- package/dist/utils/validation.js +41 -31
- package/dist/utils/validation.js.map +1 -1
- package/docs/CACHING.md +36 -2
- package/docs/DOCKER.md +24 -18
- package/docs/PERFORMANCE_MONITORING.md +49 -1
- package/docs/SECURITY_TESTING.md +30 -1
- package/docs/api/README.md +9 -1
- package/docs/api/summary.json +1 -1
- package/docs/contract-testing.md +24 -3
- package/docs/developer/GITHUB_ACTIONS_SETUP.md +8 -2
- package/docs/developer/MAINTENANCE.md +29 -3
- package/docs/developer/MIGRATION_GUIDE.md +13 -1
- package/docs/developer/NPM_AUTH_SETUP.md +13 -2
- package/docs/developer/REFACTORING.md +31 -1
- package/docs/releases/COMMUNITY_ANNOUNCEMENT_v1.1.2.md +18 -7
- package/docs/releases/RELEASE_NOTES_v1.1.2.md +31 -5
- package/docs/user-guides/DOCKER_SETUP.md +264 -0
- package/docs/user-guides/DTX_SETUP.md +327 -0
- package/docs/user-guides/NPM_SETUP.md +109 -0
- package/docs/user-guides/NPX_SETUP.md +281 -0
- package/docs/wordpress-rest-api-authentication-troubleshooting.md +13 -2
- package/package.json +27 -8
- package/src/cache/CacheInvalidation.ts +140 -132
- package/src/cache/CacheManager.ts +40 -29
- package/src/cache/HttpCacheWrapper.ts +105 -68
- package/src/cache/__tests__/CacheInvalidation.test.ts +123 -118
- package/src/cache/__tests__/CacheManager.test.ts +156 -152
- package/src/cache/__tests__/CachedWordPressClient.test.ts +131 -116
- package/src/cache/__tests__/HttpCacheWrapper.test.ts +118 -115
- package/src/cache/index.ts +13 -13
- package/src/client/CachedWordPressClient.ts +90 -80
- package/src/client/api.ts +205 -205
- package/src/client/auth.ts +80 -80
- package/src/client/managers/AuthenticationManager.ts +61 -61
- package/src/client/managers/BaseManager.ts +11 -11
- package/src/client/managers/RequestManager.ts +79 -47
- package/src/client/managers/index.ts +3 -3
- package/src/config/ConfigurationSchema.ts +44 -44
- package/src/config/ServerConfiguration.ts +39 -39
- package/src/docs/DocumentationGenerator.ts +402 -295
- package/src/docs/MarkdownFormatter.ts +94 -69
- package/src/docs/index.ts +4 -4
- package/src/index.ts +24 -21
- package/src/performance/MetricsCollector.ts +90 -58
- package/src/performance/PerformanceAnalytics.ts +386 -262
- package/src/performance/PerformanceMonitor.ts +152 -118
- package/src/performance/index.ts +9 -9
- package/src/security/InputValidator.ts +148 -91
- package/src/security/SecurityConfig.ts +94 -94
- package/src/server/ConnectionTester.ts +21 -15
- package/src/server/ToolRegistry.ts +64 -51
- package/src/server.ts +2 -2
- package/src/tools/BaseToolManager.ts +6 -6
- package/src/tools/auth.ts +42 -37
- package/src/tools/cache.ts +85 -81
- package/src/tools/comments.ts +93 -91
- package/src/tools/index.ts +10 -10
- package/src/tools/media.ts +89 -89
- package/src/tools/pages.ts +89 -87
- package/src/tools/performance.ts +443 -352
- package/src/tools/posts.ts +109 -107
- package/src/tools/site.ts +86 -77
- package/src/tools/taxonomies.ts +102 -102
- package/src/tools/users.ts +77 -77
- package/src/types/client.ts +157 -60
- package/src/types/index.ts +49 -27
- package/src/types/mcp.ts +15 -15
- package/src/types/wordpress.ts +57 -29
- package/src/utils/debug.ts +37 -37
- package/src/utils/error.ts +47 -25
- package/src/utils/toolWrapper.ts +12 -8
- package/src/utils/validation.ts +116 -65
- package/dist/client/WordPressClient.d.ts +0 -81
- package/dist/client/WordPressClient.d.ts.map +0 -1
- package/dist/client/WordPressClient.js +0 -354
- package/dist/client/WordPressClient.js.map +0 -1
- package/dist/performance/AnomalyDetector.d.ts +0 -63
- package/dist/performance/AnomalyDetector.d.ts.map +0 -1
- package/dist/performance/AnomalyDetector.js +0 -222
- package/dist/performance/AnomalyDetector.js.map +0 -1
- package/dist/performance/BenchmarkAnalyzer.d.ts +0 -67
- package/dist/performance/BenchmarkAnalyzer.d.ts.map +0 -1
- package/dist/performance/BenchmarkAnalyzer.js +0 -301
- package/dist/performance/BenchmarkAnalyzer.js.map +0 -1
- package/dist/performance/TrendAnalyzer.d.ts +0 -69
- package/dist/performance/TrendAnalyzer.d.ts.map +0 -1
- package/dist/performance/TrendAnalyzer.js +0 -203
- package/dist/performance/TrendAnalyzer.js.map +0 -1
- package/dist/tools/BaseToolClass.d.ts +0 -76
- package/dist/tools/BaseToolClass.d.ts.map +0 -1
- package/dist/tools/BaseToolClass.js +0 -104
- package/dist/tools/BaseToolClass.js.map +0 -1
- package/dist/tools/base.d.ts +0 -37
- package/dist/tools/base.d.ts.map +0 -1
- package/dist/tools/base.js +0 -60
- package/dist/tools/base.js.map +0 -1
- package/docs/user-guides/CLAUDE_DESKTOP_SETUP.md +0 -187
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
* Tests for CacheManager
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import { CacheManager, CachePresets } from
|
|
5
|
+
import { CacheManager, CachePresets } from "../CacheManager.js";
|
|
6
6
|
|
|
7
|
-
describe(
|
|
7
|
+
describe("CacheManager", () => {
|
|
8
8
|
let cacheManager: CacheManager;
|
|
9
9
|
|
|
10
10
|
beforeEach(() => {
|
|
@@ -12,7 +12,7 @@ describe('CacheManager', () => {
|
|
|
12
12
|
maxSize: 100,
|
|
13
13
|
defaultTTL: 1000,
|
|
14
14
|
enableLRU: true,
|
|
15
|
-
enableStats: true
|
|
15
|
+
enableStats: true,
|
|
16
16
|
});
|
|
17
17
|
});
|
|
18
18
|
|
|
@@ -20,10 +20,10 @@ describe('CacheManager', () => {
|
|
|
20
20
|
cacheManager.clear();
|
|
21
21
|
});
|
|
22
22
|
|
|
23
|
-
describe(
|
|
24
|
-
test(
|
|
25
|
-
const key =
|
|
26
|
-
const value = { data:
|
|
23
|
+
describe("Basic Operations", () => {
|
|
24
|
+
test("should store and retrieve values", () => {
|
|
25
|
+
const key = "test-key";
|
|
26
|
+
const value = { data: "test value" };
|
|
27
27
|
|
|
28
28
|
cacheManager.set(key, value);
|
|
29
29
|
const retrieved = cacheManager.get(key);
|
|
@@ -31,227 +31,227 @@ describe('CacheManager', () => {
|
|
|
31
31
|
expect(retrieved).toEqual(value);
|
|
32
32
|
});
|
|
33
33
|
|
|
34
|
-
test(
|
|
35
|
-
const result = cacheManager.get(
|
|
34
|
+
test("should return null for non-existent keys", () => {
|
|
35
|
+
const result = cacheManager.get("non-existent");
|
|
36
36
|
expect(result).toBeNull();
|
|
37
37
|
});
|
|
38
38
|
|
|
39
|
-
test(
|
|
40
|
-
const key =
|
|
39
|
+
test("should check if key exists", () => {
|
|
40
|
+
const key = "exists-test";
|
|
41
41
|
expect(cacheManager.has(key)).toBe(false);
|
|
42
42
|
|
|
43
|
-
cacheManager.set(key,
|
|
43
|
+
cacheManager.set(key, "value");
|
|
44
44
|
expect(cacheManager.has(key)).toBe(true);
|
|
45
45
|
});
|
|
46
46
|
|
|
47
|
-
test(
|
|
48
|
-
const key =
|
|
49
|
-
cacheManager.set(key,
|
|
50
|
-
|
|
47
|
+
test("should delete entries", () => {
|
|
48
|
+
const key = "delete-test";
|
|
49
|
+
cacheManager.set(key, "value");
|
|
50
|
+
|
|
51
51
|
expect(cacheManager.has(key)).toBe(true);
|
|
52
52
|
const deleted = cacheManager.delete(key);
|
|
53
|
-
|
|
53
|
+
|
|
54
54
|
expect(deleted).toBe(true);
|
|
55
55
|
expect(cacheManager.has(key)).toBe(false);
|
|
56
56
|
});
|
|
57
57
|
|
|
58
|
-
test(
|
|
59
|
-
cacheManager.set(
|
|
60
|
-
cacheManager.set(
|
|
61
|
-
|
|
58
|
+
test("should clear all entries", () => {
|
|
59
|
+
cacheManager.set("key1", "value1");
|
|
60
|
+
cacheManager.set("key2", "value2");
|
|
61
|
+
|
|
62
62
|
expect(cacheManager.getStats().totalSize).toBe(2);
|
|
63
|
-
|
|
63
|
+
|
|
64
64
|
cacheManager.clear();
|
|
65
|
-
|
|
65
|
+
|
|
66
66
|
expect(cacheManager.getStats().totalSize).toBe(0);
|
|
67
|
-
expect(cacheManager.has(
|
|
68
|
-
expect(cacheManager.has(
|
|
67
|
+
expect(cacheManager.has("key1")).toBe(false);
|
|
68
|
+
expect(cacheManager.has("key2")).toBe(false);
|
|
69
69
|
});
|
|
70
70
|
});
|
|
71
71
|
|
|
72
|
-
describe(
|
|
73
|
-
test(
|
|
74
|
-
const key =
|
|
72
|
+
describe("TTL and Expiration", () => {
|
|
73
|
+
test("should expire entries after TTL", async () => {
|
|
74
|
+
const key = "ttl-test";
|
|
75
75
|
const shortTTL = 50; // 50ms
|
|
76
|
-
|
|
77
|
-
cacheManager.set(key,
|
|
78
|
-
expect(cacheManager.get(key)).toBe(
|
|
79
|
-
|
|
76
|
+
|
|
77
|
+
cacheManager.set(key, "value", shortTTL);
|
|
78
|
+
expect(cacheManager.get(key)).toBe("value");
|
|
79
|
+
|
|
80
80
|
// Wait for expiration
|
|
81
|
-
await new Promise(resolve => setTimeout(resolve, 100));
|
|
82
|
-
|
|
81
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
82
|
+
|
|
83
83
|
expect(cacheManager.get(key)).toBeNull();
|
|
84
84
|
});
|
|
85
85
|
|
|
86
|
-
test(
|
|
87
|
-
const key =
|
|
86
|
+
test("should not expire entries before TTL", () => {
|
|
87
|
+
const key = "no-expire-test";
|
|
88
88
|
const longTTL = 10000; // 10 seconds
|
|
89
|
-
|
|
90
|
-
cacheManager.set(key,
|
|
91
|
-
expect(cacheManager.get(key)).toBe(
|
|
89
|
+
|
|
90
|
+
cacheManager.set(key, "value", longTTL);
|
|
91
|
+
expect(cacheManager.get(key)).toBe("value");
|
|
92
92
|
});
|
|
93
93
|
|
|
94
|
-
test(
|
|
95
|
-
const key =
|
|
96
|
-
cacheManager.set(key,
|
|
97
|
-
|
|
94
|
+
test("should use default TTL when not specified", () => {
|
|
95
|
+
const key = "default-ttl-test";
|
|
96
|
+
cacheManager.set(key, "value");
|
|
97
|
+
|
|
98
98
|
const entry = cacheManager.getEntry(key);
|
|
99
99
|
expect(entry?.ttl).toBe(1000);
|
|
100
100
|
});
|
|
101
101
|
});
|
|
102
102
|
|
|
103
|
-
describe(
|
|
104
|
-
test(
|
|
105
|
-
const siteId =
|
|
106
|
-
const endpoint =
|
|
107
|
-
const params = { per_page: 10, status:
|
|
108
|
-
|
|
103
|
+
describe("Key Generation", () => {
|
|
104
|
+
test("should generate consistent keys for same parameters", () => {
|
|
105
|
+
const siteId = "site1";
|
|
106
|
+
const endpoint = "posts";
|
|
107
|
+
const params = { per_page: 10, status: "publish" };
|
|
108
|
+
|
|
109
109
|
const key1 = cacheManager.generateKey(siteId, endpoint, params);
|
|
110
110
|
const key2 = cacheManager.generateKey(siteId, endpoint, params);
|
|
111
|
-
|
|
111
|
+
|
|
112
112
|
expect(key1).toBe(key2);
|
|
113
113
|
});
|
|
114
114
|
|
|
115
|
-
test(
|
|
116
|
-
const siteId =
|
|
117
|
-
const endpoint =
|
|
115
|
+
test("should generate different keys for different parameters", () => {
|
|
116
|
+
const siteId = "site1";
|
|
117
|
+
const endpoint = "posts";
|
|
118
118
|
const params1 = { per_page: 10 };
|
|
119
119
|
const params2 = { per_page: 20 };
|
|
120
|
-
|
|
120
|
+
|
|
121
121
|
const key1 = cacheManager.generateKey(siteId, endpoint, params1);
|
|
122
122
|
const key2 = cacheManager.generateKey(siteId, endpoint, params2);
|
|
123
|
-
|
|
123
|
+
|
|
124
124
|
expect(key1).not.toBe(key2);
|
|
125
125
|
});
|
|
126
126
|
|
|
127
|
-
test(
|
|
128
|
-
const endpoint =
|
|
127
|
+
test("should include site ID in key", () => {
|
|
128
|
+
const endpoint = "posts";
|
|
129
129
|
const params = { per_page: 10 };
|
|
130
|
-
|
|
131
|
-
const key1 = cacheManager.generateKey(
|
|
132
|
-
const key2 = cacheManager.generateKey(
|
|
133
|
-
|
|
134
|
-
expect(key1).toContain(
|
|
135
|
-
expect(key2).toContain(
|
|
130
|
+
|
|
131
|
+
const key1 = cacheManager.generateKey("site1", endpoint, params);
|
|
132
|
+
const key2 = cacheManager.generateKey("site2", endpoint, params);
|
|
133
|
+
|
|
134
|
+
expect(key1).toContain("site1:");
|
|
135
|
+
expect(key2).toContain("site2:");
|
|
136
136
|
expect(key1).not.toBe(key2);
|
|
137
137
|
});
|
|
138
138
|
|
|
139
|
-
test(
|
|
140
|
-
const key1 = cacheManager.generateKey(
|
|
141
|
-
const key2 = cacheManager.generateKey(
|
|
142
|
-
const key3 = cacheManager.generateKey(
|
|
143
|
-
|
|
139
|
+
test("should handle undefined parameters", () => {
|
|
140
|
+
const key1 = cacheManager.generateKey("site1", "posts");
|
|
141
|
+
const key2 = cacheManager.generateKey("site1", "posts", undefined);
|
|
142
|
+
const key3 = cacheManager.generateKey("site1", "posts", {});
|
|
143
|
+
|
|
144
144
|
expect(key1).toBe(key2);
|
|
145
145
|
expect(key1).toBe(key3);
|
|
146
146
|
});
|
|
147
147
|
});
|
|
148
148
|
|
|
149
|
-
describe(
|
|
150
|
-
test(
|
|
151
|
-
cacheManager.set(
|
|
152
|
-
cacheManager.set(
|
|
153
|
-
cacheManager.set(
|
|
154
|
-
|
|
155
|
-
const cleared = cacheManager.clearSite(
|
|
156
|
-
|
|
149
|
+
describe("Site-Specific Operations", () => {
|
|
150
|
+
test("should clear cache for specific site", () => {
|
|
151
|
+
cacheManager.set("site1:posts:abc123", "value1");
|
|
152
|
+
cacheManager.set("site1:pages:def456", "value2");
|
|
153
|
+
cacheManager.set("site2:posts:ghi789", "value3");
|
|
154
|
+
|
|
155
|
+
const cleared = cacheManager.clearSite("site1");
|
|
156
|
+
|
|
157
157
|
expect(cleared).toBe(2);
|
|
158
|
-
expect(cacheManager.has(
|
|
159
|
-
expect(cacheManager.has(
|
|
160
|
-
expect(cacheManager.has(
|
|
158
|
+
expect(cacheManager.has("site1:posts:abc123")).toBe(false);
|
|
159
|
+
expect(cacheManager.has("site1:pages:def456")).toBe(false);
|
|
160
|
+
expect(cacheManager.has("site2:posts:ghi789")).toBe(true);
|
|
161
161
|
});
|
|
162
162
|
|
|
163
|
-
test(
|
|
164
|
-
cacheManager.set(
|
|
165
|
-
cacheManager.set(
|
|
166
|
-
cacheManager.set(
|
|
167
|
-
|
|
163
|
+
test("should clear cache matching pattern", () => {
|
|
164
|
+
cacheManager.set("site1:posts:list", "value1");
|
|
165
|
+
cacheManager.set("site1:posts:123", "value2");
|
|
166
|
+
cacheManager.set("site1:pages:456", "value3");
|
|
167
|
+
|
|
168
168
|
const pattern = /site1:posts/;
|
|
169
169
|
const cleared = cacheManager.clearPattern(pattern);
|
|
170
|
-
|
|
170
|
+
|
|
171
171
|
expect(cleared).toBe(2);
|
|
172
|
-
expect(cacheManager.has(
|
|
173
|
-
expect(cacheManager.has(
|
|
174
|
-
expect(cacheManager.has(
|
|
172
|
+
expect(cacheManager.has("site1:posts:list")).toBe(false);
|
|
173
|
+
expect(cacheManager.has("site1:posts:123")).toBe(false);
|
|
174
|
+
expect(cacheManager.has("site1:pages:456")).toBe(true);
|
|
175
175
|
});
|
|
176
176
|
});
|
|
177
177
|
|
|
178
|
-
describe(
|
|
179
|
-
test(
|
|
178
|
+
describe("LRU Eviction", () => {
|
|
179
|
+
test("should evict least recently used items when at capacity", () => {
|
|
180
180
|
const smallCache = new CacheManager({
|
|
181
181
|
maxSize: 3,
|
|
182
182
|
defaultTTL: 10000,
|
|
183
183
|
enableLRU: true,
|
|
184
|
-
enableStats: true
|
|
184
|
+
enableStats: true,
|
|
185
185
|
});
|
|
186
186
|
|
|
187
187
|
// Fill cache to capacity
|
|
188
|
-
smallCache.set(
|
|
189
|
-
smallCache.set(
|
|
190
|
-
smallCache.set(
|
|
191
|
-
|
|
188
|
+
smallCache.set("key1", "value1");
|
|
189
|
+
smallCache.set("key2", "value2");
|
|
190
|
+
smallCache.set("key3", "value3");
|
|
191
|
+
|
|
192
192
|
expect(smallCache.getStats().totalSize).toBe(3);
|
|
193
|
-
|
|
193
|
+
|
|
194
194
|
// Access key1 to make it more recently used
|
|
195
|
-
smallCache.get(
|
|
196
|
-
|
|
195
|
+
smallCache.get("key1");
|
|
196
|
+
|
|
197
197
|
// Add new item, should evict key2 (least recently used)
|
|
198
|
-
smallCache.set(
|
|
199
|
-
|
|
200
|
-
expect(smallCache.has(
|
|
201
|
-
expect(smallCache.has(
|
|
202
|
-
expect(smallCache.has(
|
|
203
|
-
expect(smallCache.has(
|
|
198
|
+
smallCache.set("key4", "value4");
|
|
199
|
+
|
|
200
|
+
expect(smallCache.has("key1")).toBe(true); // Recently accessed
|
|
201
|
+
expect(smallCache.has("key2")).toBe(false); // Should be evicted
|
|
202
|
+
expect(smallCache.has("key3")).toBe(true); // Recently added
|
|
203
|
+
expect(smallCache.has("key4")).toBe(true); // Just added
|
|
204
204
|
expect(smallCache.getStats().evictions).toBe(1);
|
|
205
205
|
});
|
|
206
206
|
});
|
|
207
207
|
|
|
208
|
-
describe(
|
|
209
|
-
test(
|
|
210
|
-
const key =
|
|
211
|
-
const value = { data:
|
|
212
|
-
const etag =
|
|
213
|
-
|
|
208
|
+
describe("ETags and Conditional Requests", () => {
|
|
209
|
+
test("should store and retrieve ETags", () => {
|
|
210
|
+
const key = "etag-test";
|
|
211
|
+
const value = { data: "test" };
|
|
212
|
+
const etag = "\"abc123\"";
|
|
213
|
+
|
|
214
214
|
cacheManager.set(key, value, 1000, etag);
|
|
215
|
-
|
|
215
|
+
|
|
216
216
|
const entry = cacheManager.getEntry(key);
|
|
217
217
|
expect(entry?.etag).toBe(etag);
|
|
218
218
|
});
|
|
219
219
|
|
|
220
|
-
test(
|
|
221
|
-
const key =
|
|
222
|
-
const etag =
|
|
223
|
-
const lastModified =
|
|
224
|
-
|
|
225
|
-
cacheManager.set(key, { data:
|
|
226
|
-
|
|
220
|
+
test("should support conditional request headers", () => {
|
|
221
|
+
const key = "conditional-test";
|
|
222
|
+
const etag = "\"abc123\"";
|
|
223
|
+
const lastModified = "Wed, 21 Oct 2015 07:28:00 GMT";
|
|
224
|
+
|
|
225
|
+
cacheManager.set(key, { data: "test" }, 1000, etag, lastModified);
|
|
226
|
+
|
|
227
227
|
expect(cacheManager.supportsConditionalRequest(key)).toBe(true);
|
|
228
|
-
|
|
228
|
+
|
|
229
229
|
const headers = cacheManager.getConditionalHeaders(key);
|
|
230
|
-
expect(headers[
|
|
231
|
-
expect(headers[
|
|
230
|
+
expect(headers["If-None-Match"]).toBe(etag);
|
|
231
|
+
expect(headers["If-Modified-Since"]).toBe(lastModified);
|
|
232
232
|
});
|
|
233
233
|
|
|
234
|
-
test(
|
|
235
|
-
const key =
|
|
236
|
-
cacheManager.set(key, { data:
|
|
237
|
-
|
|
234
|
+
test("should not support conditional requests without ETags", () => {
|
|
235
|
+
const key = "no-etag-test";
|
|
236
|
+
cacheManager.set(key, { data: "test" });
|
|
237
|
+
|
|
238
238
|
expect(cacheManager.supportsConditionalRequest(key)).toBe(false);
|
|
239
239
|
expect(cacheManager.getConditionalHeaders(key)).toEqual({});
|
|
240
240
|
});
|
|
241
241
|
});
|
|
242
242
|
|
|
243
|
-
describe(
|
|
244
|
-
test(
|
|
245
|
-
const key =
|
|
246
|
-
|
|
243
|
+
describe("Statistics", () => {
|
|
244
|
+
test("should track cache hits and misses", () => {
|
|
245
|
+
const key = "stats-test";
|
|
246
|
+
|
|
247
247
|
// Miss
|
|
248
248
|
cacheManager.get(key);
|
|
249
249
|
let stats = cacheManager.getStats();
|
|
250
250
|
expect(stats.misses).toBe(1);
|
|
251
251
|
expect(stats.hits).toBe(0);
|
|
252
|
-
|
|
252
|
+
|
|
253
253
|
// Hit
|
|
254
|
-
cacheManager.set(key,
|
|
254
|
+
cacheManager.set(key, "value");
|
|
255
255
|
cacheManager.get(key);
|
|
256
256
|
stats = cacheManager.getStats();
|
|
257
257
|
expect(stats.hits).toBe(1);
|
|
@@ -259,27 +259,27 @@ describe('CacheManager', () => {
|
|
|
259
259
|
expect(stats.hitRate).toBe(0.5);
|
|
260
260
|
});
|
|
261
261
|
|
|
262
|
-
test(
|
|
262
|
+
test("should track total size", () => {
|
|
263
263
|
const stats1 = cacheManager.getStats();
|
|
264
264
|
expect(stats1.totalSize).toBe(0);
|
|
265
|
-
|
|
266
|
-
cacheManager.set(
|
|
267
|
-
cacheManager.set(
|
|
268
|
-
|
|
265
|
+
|
|
266
|
+
cacheManager.set("key1", "value1");
|
|
267
|
+
cacheManager.set("key2", "value2");
|
|
268
|
+
|
|
269
269
|
const stats2 = cacheManager.getStats();
|
|
270
270
|
expect(stats2.totalSize).toBe(2);
|
|
271
271
|
});
|
|
272
272
|
|
|
273
|
-
test(
|
|
274
|
-
cacheManager.set(
|
|
275
|
-
|
|
273
|
+
test("should calculate hit rate correctly", () => {
|
|
274
|
+
cacheManager.set("key1", "value1");
|
|
275
|
+
|
|
276
276
|
// 3 hits, 2 misses = 60% hit rate
|
|
277
|
-
cacheManager.get(
|
|
278
|
-
cacheManager.get(
|
|
279
|
-
cacheManager.get(
|
|
280
|
-
cacheManager.get(
|
|
281
|
-
cacheManager.get(
|
|
282
|
-
|
|
277
|
+
cacheManager.get("key1"); // hit
|
|
278
|
+
cacheManager.get("key1"); // hit
|
|
279
|
+
cacheManager.get("key1"); // hit
|
|
280
|
+
cacheManager.get("key2"); // miss
|
|
281
|
+
cacheManager.get("key3"); // miss
|
|
282
|
+
|
|
283
283
|
const stats = cacheManager.getStats();
|
|
284
284
|
expect(stats.hits).toBe(3);
|
|
285
285
|
expect(stats.misses).toBe(2);
|
|
@@ -287,14 +287,18 @@ describe('CacheManager', () => {
|
|
|
287
287
|
});
|
|
288
288
|
});
|
|
289
289
|
|
|
290
|
-
describe(
|
|
291
|
-
test(
|
|
290
|
+
describe("Cache Presets", () => {
|
|
291
|
+
test("should have predefined cache presets", () => {
|
|
292
292
|
expect(CachePresets.STATIC.ttl).toBeGreaterThan(CachePresets.DYNAMIC.ttl);
|
|
293
|
-
expect(CachePresets.SEMI_STATIC.ttl).toBeGreaterThan(
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
expect(CachePresets.
|
|
297
|
-
|
|
293
|
+
expect(CachePresets.SEMI_STATIC.ttl).toBeGreaterThan(
|
|
294
|
+
CachePresets.DYNAMIC.ttl,
|
|
295
|
+
);
|
|
296
|
+
expect(CachePresets.SESSION.ttl).toBeGreaterThan(
|
|
297
|
+
CachePresets.DYNAMIC.ttl,
|
|
298
|
+
);
|
|
299
|
+
|
|
300
|
+
expect(CachePresets.STATIC.cacheControl).toContain("public");
|
|
301
|
+
expect(CachePresets.SESSION.cacheControl).toContain("private");
|
|
298
302
|
});
|
|
299
303
|
});
|
|
300
304
|
});
|