@teamvelix/cache-redis 0.1.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 (3) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +75 -0
  3. package/package.json +47 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Velix Team
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,75 @@
1
+ # @velix/cache-redis
2
+
3
+ Redis cache adapter for Velix — implements `ICacheAdapter` via [ioredis](https://github.com/redis/ioredis).
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pnpm add @velix/cache-redis ioredis
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```ts
14
+ // velix.config.ts
15
+ import { defineConfig } from 'velix';
16
+ import { RedisCacheAdapter } from '@velix/cache-redis';
17
+
18
+ export default defineConfig({
19
+ cache: {
20
+ adapter: new RedisCacheAdapter({
21
+ url: process.env.REDIS_URL ?? 'redis://localhost:6379',
22
+ }),
23
+ },
24
+ });
25
+ ```
26
+
27
+ ## Configuration
28
+
29
+ | Option | Type | Default | Description |
30
+ |---|---|---|---|
31
+ | `url` | `string` | `'redis://localhost:6379'` | URL de connexion Redis |
32
+ | `client` | `Redis` | — | Instance ioredis pré-configurée (prioritaire sur `url`) |
33
+ | `keyPrefix` | `string` | `'velix:'` | Préfixe appliqué à toutes les clés |
34
+ | `defaultTTL` | `number` | `undefined` | TTL par défaut en millisecondes |
35
+
36
+ ## Features
37
+
38
+ - **TTL natif Redis** via la commande `PX` (précision milliseconde)
39
+ - **Invalidation par tag** avec un Set Redis par tag, suppression **atomique** via script Lua
40
+ - **Suppression par préfixe** via `SCAN` non-bloquant (ne jamais utiliser `KEYS` en prod)
41
+ - **Clear sélectif** : supprime uniquement les clés `velix:*`, sans impacter les autres apps
42
+
43
+ ## Cache Tag Invalidation
44
+
45
+ ```ts
46
+ import { VelixCache } from 'velix';
47
+ import { RedisCacheAdapter } from '@velix/cache-redis';
48
+
49
+ const cache = new VelixCache(new RedisCacheAdapter({ url: process.env.REDIS_URL }));
50
+
51
+ // Stocker avec des tags
52
+ await cache.unstable_cache(fetchProducts, ['products'], {
53
+ tags: ['products', 'featured'],
54
+ revalidate: 300, // 5 minutes
55
+ })();
56
+
57
+ // Invalider tous les produits (ex: après un webhook CMS)
58
+ await cache.revalidateTag('products');
59
+ ```
60
+
61
+ ## Architecture
62
+
63
+ Ce package est volontairement indépendant de `velix-core` pour permettre son utilisation
64
+ dans des contextes non-Velix. Il expose sa propre copie de l'interface `ICacheAdapter`.
65
+
66
+ ```
67
+ @velix/cache-redis
68
+ ├── src/
69
+ │ ├── redis.adapter.ts ← Implémentation principale
70
+ │ ├── types.ts ← Types exportés
71
+ │ ├── index.ts ← Point d'entrée
72
+ │ └── lua/
73
+ │ ├── delete-by-tag.lua ← Script Lua atomique (référence)
74
+ │ └── delete-by-prefix.lua ← Script Lua (référence)
75
+ ```
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "@teamvelix/cache-redis",
3
+ "version": "0.1.0",
4
+ "description": "Redis cache adapter for Velix — implements ICacheAdapter via ioredis",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "type": "module",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/index.js",
11
+ "types": "./dist/index.d.ts"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist",
16
+ "README.md",
17
+ "LICENSE"
18
+ ],
19
+ "keywords": [
20
+ "velix",
21
+ "cache",
22
+ "redis",
23
+ "ioredis"
24
+ ],
25
+ "author": "velixteam",
26
+ "license": "MIT",
27
+ "peerDependencies": {
28
+ "ioredis": ">=5.0.0"
29
+ },
30
+ "devDependencies": {
31
+ "ioredis": "^5.11.1",
32
+ "ioredis-mock": "^8.9.0",
33
+ "tsup": "^8.3.6",
34
+ "typescript": "^5.4.5",
35
+ "vitest": "^2.1.9"
36
+ },
37
+ "publishConfig": {
38
+ "access": "public"
39
+ },
40
+ "scripts": {
41
+ "build": "tsup src/index.ts --format esm --dts --clean",
42
+ "dev": "tsup src/index.ts --format esm --dts --watch",
43
+ "typecheck": "tsc --noEmit",
44
+ "test": "vitest run",
45
+ "test:watch": "vitest"
46
+ }
47
+ }