@lytjs/cache 6.8.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.
Files changed (2) hide show
  1. package/README.md +77 -0
  2. package/package.json +49 -0
package/README.md ADDED
@@ -0,0 +1,77 @@
1
+ # @lytjs/cache
2
+
3
+ LytJS 统一缓存系统,提供多层缓存支持(Memory → Redis → HTTP)。
4
+
5
+ ## 功能特性
6
+
7
+ - 🚀 内存缓存,高性能
8
+ - 🏷️ 缓存标签支持
9
+ - ⏱️ TTL 过期控制
10
+ - 📊 缓存统计信息
11
+ - 📦 多层缓存架构
12
+
13
+ ## 安装
14
+
15
+ ```bash
16
+ pnpm add @lytjs/cache
17
+ ```
18
+
19
+ ## 使用示例
20
+
21
+ ```typescript
22
+ import { createCache } from '@lytjs/cache';
23
+
24
+ // 创建内存缓存
25
+ const cache = createCache();
26
+
27
+ // 设置缓存
28
+ await cache.set('key', 'value', {
29
+ ttl: 3600000, // 1 小时
30
+ tags: ['user', 'profile'],
31
+ });
32
+
33
+ // 获取缓存
34
+ const value = await cache.get('key');
35
+
36
+ // 按标签无效化
37
+ await cache.invalidateTag('user');
38
+
39
+ // 获取统计信息
40
+ const stats = await cache.getStats();
41
+ console.log(stats.hitRate);
42
+ ```
43
+
44
+ ## 多层缓存
45
+
46
+ ```typescript
47
+ import { createCache } from '@lytjs/cache';
48
+
49
+ const cache = createCache({
50
+ type: 'multi',
51
+ config: {
52
+ memory: { ttl: 300000 }, // 5 分钟
53
+ redis: { host: 'localhost', port: 6379 },
54
+ },
55
+ });
56
+ ```
57
+
58
+ ## API
59
+
60
+ ### `createCache(options)`
61
+
62
+ 创建缓存实例
63
+
64
+ ### `Cache` 接口
65
+
66
+ - `get<T>(key): Promise<T | undefined>`
67
+ - `set<T>(key, value, options?): Promise<void>`
68
+ - `delete(key): Promise<boolean>`
69
+ - `has(key): Promise<boolean>`
70
+ - `clear(): Promise<void>`
71
+ - `invalidateTag(tag): Promise<void>`
72
+ - `invalidateTags(tags): Promise<void>`
73
+ - `getStats(): Promise<CacheStats>`
74
+
75
+ ## License
76
+
77
+ MIT
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "@lytjs/cache",
3
+ "version": "6.8.0",
4
+ "description": "LytJS unified caching system with memory, Redis, and HTTP cache support",
5
+ "type": "module",
6
+ "main": "./dist/index.cjs",
7
+ "module": "./dist/index.mjs",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.mjs",
13
+ "require": "./dist/index.cjs"
14
+ }
15
+ },
16
+ "files": [
17
+ "dist"
18
+ ],
19
+ "scripts": {
20
+ "build": "tsup",
21
+ "dev": "tsup --watch",
22
+ "test": "vitest run",
23
+ "type-check": "tsc --noEmit",
24
+ "clean": "rm -rf dist"
25
+ },
26
+ "dependencies": {
27
+ "@lytjs/common-cache": "workspace:*",
28
+ "@lytjs/common-is": "workspace:*"
29
+ },
30
+ "devDependencies": {
31
+ "tsup": "^8.0.0",
32
+ "typescript": "^5.4.0",
33
+ "vitest": "^3.0.0"
34
+ },
35
+ "license": "MIT",
36
+ "repository": {
37
+ "type": "git",
38
+ "url": "https://gitee.com/lytjs/lytjs.git",
39
+ "directory": "packages/ecosystem/packages/ssr-kit/packages/cache"
40
+ },
41
+ "keywords": [
42
+ "lytjs",
43
+ "cache",
44
+ "caching",
45
+ "memory-cache",
46
+ "redis-cache",
47
+ "http-cache"
48
+ ]
49
+ }