@agrodt/astro-redis-cache-provider 0.0.1 → 0.1.1
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/LICENSE +21 -0
- package/README.md +73 -43
- package/dist/config.d.ts +8 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +12 -0
- package/dist/config.js.map +1 -0
- package/dist/runtime.d.ts +74 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +461 -0
- package/dist/runtime.js.map +1 -0
- package/dist/schemas.d.ts +20 -0
- package/dist/schemas.d.ts.map +1 -0
- package/dist/schemas.js +145 -0
- package/dist/schemas.js.map +1 -0
- package/package.json +74 -7
- package/src/config.ts +18 -0
- package/src/runtime.ts +711 -0
- package/src/schemas.ts +174 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 AgroDT lab
|
|
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
CHANGED
|
@@ -1,45 +1,75 @@
|
|
|
1
1
|
# @agrodt/astro-redis-cache-provider
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
3
|
+
[](https://github.com/AgroDT/astro-redis-cache-provider/actions/workflows/ci.yml)
|
|
4
|
+
[](https://coveralls.io/github/AgroDT/astro-redis-cache-provider?branch=main)
|
|
5
|
+
[](https://www.npmjs.com/package/@agrodt/astro-redis-cache-provider)
|
|
6
|
+
[](./LICENSE)
|
|
7
|
+
[](https://www.npmjs.com/package/@agrodt/astro-redis-cache-provider)
|
|
8
|
+
|
|
9
|
+
Custom Redis cache provider for Astro route caching,
|
|
10
|
+
powered by [`node-redis`](https://github.com/redis/node-redis).
|
|
11
|
+
|
|
12
|
+
> [!CAUTION]
|
|
13
|
+
> **Disclaimer:** This project is 102% generated by an LLM. The author assumes
|
|
14
|
+
> absolutely no responsibility for any consequences of using it - especially,
|
|
15
|
+
> but not limited to, the mysterious harm that may befall nearby kittens once
|
|
16
|
+
> you deploy this in production. Proceed at your own risk!
|
|
17
|
+
|
|
18
|
+
## Install
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
pnpm add @agrodt/astro-redis-cache-provider
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
`node-redis` already comes as a dependency of this package. You only need
|
|
25
|
+
a reachable Redis server.
|
|
26
|
+
|
|
27
|
+
## Usage
|
|
28
|
+
|
|
29
|
+
```ts
|
|
30
|
+
// astro.config.mjs
|
|
31
|
+
import { defineConfig } from "astro/config";
|
|
32
|
+
import { redisCache } from "@agrodt/astro-redis-cache-provider/config";
|
|
33
|
+
|
|
34
|
+
export default defineConfig({
|
|
35
|
+
experimental: {
|
|
36
|
+
cache: {
|
|
37
|
+
provider: redisCache({
|
|
38
|
+
url: () => process.env.REDIS_URL,
|
|
39
|
+
keyPrefix: "astro:cache",
|
|
40
|
+
}),
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Options
|
|
47
|
+
|
|
48
|
+
```ts
|
|
49
|
+
type RedisCacheProviderOptions = {
|
|
50
|
+
url?: string | (() => string | undefined);
|
|
51
|
+
keyPrefix?: string;
|
|
52
|
+
revalidateLockTtl?: number;
|
|
53
|
+
ignoredVaryHeaders?: Iterable<string>;
|
|
54
|
+
query?: {
|
|
55
|
+
include?: string[];
|
|
56
|
+
exclude?: string[];
|
|
57
|
+
sort?: boolean;
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
- `url`: Redis URL string or runtime factory (`() => string | undefined`),
|
|
63
|
+
for example `redis://localhost:6379` or `() => process.env.REDIS_URL`.
|
|
64
|
+
- `keyPrefix`: Prefix for all Redis keys. Default: `astro:cache`.
|
|
65
|
+
- `revalidateLockTtl`: Lock lifetime in seconds for stale background
|
|
66
|
+
revalidation. Default: `30`.
|
|
67
|
+
- `ignoredVaryHeaders`: Additional `Vary` headers to ignore during cache
|
|
68
|
+
matching (for example `["cookie"]`). `set-cookie` is always ignored.
|
|
69
|
+
- `query`: Same query normalization semantics as Astro memory provider
|
|
70
|
+
(`include`/`exclude` are mutually exclusive).
|
|
71
|
+
|
|
72
|
+
## Example
|
|
73
|
+
|
|
74
|
+
See [example](./example/README.md) for a runnable Astro app that
|
|
75
|
+
demonstrates `MISS`/`HIT` behavior and manual invalidation.
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { CacheProviderConfig } from "astro";
|
|
2
|
+
import type { RedisCacheProviderOptions } from "./runtime.js";
|
|
3
|
+
/**
|
|
4
|
+
* Creates Astro cache provider configuration for the Redis runtime provider.
|
|
5
|
+
*/
|
|
6
|
+
export declare function redisCache(config?: RedisCacheProviderOptions): CacheProviderConfig<RedisCacheProviderOptions>;
|
|
7
|
+
export default redisCache;
|
|
8
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,OAAO,CAAC;AAEjD,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAC;AAE9D;;GAEG;AACH,wBAAgB,UAAU,CACxB,MAAM,GAAE,yBAA8B,GACrC,mBAAmB,CAAC,yBAAyB,CAAC,CAMhD;AAED,eAAe,UAAU,CAAC"}
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates Astro cache provider configuration for the Redis runtime provider.
|
|
3
|
+
*/
|
|
4
|
+
export function redisCache(config = {}) {
|
|
5
|
+
return {
|
|
6
|
+
name: "redis",
|
|
7
|
+
entrypoint: "@agrodt/astro-redis-cache-provider/runtime",
|
|
8
|
+
config,
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
export default redisCache;
|
|
12
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,MAAM,UAAU,UAAU,CACxB,MAAM,GAA8B,EAAE;IAEtC,OAAO;QACL,IAAI,EAAE,OAAO;QACb,UAAU,EAAE,4CAA4C;QACxD,MAAM;KACP,CAAC;AACJ,CAAC;AAED,eAAe,UAAU,CAAC"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { CacheProvider } from "astro";
|
|
2
|
+
export type { RedisCacheProvider, RedisCacheProviderOptions };
|
|
3
|
+
export { createRedisCacheProvider, createRedisCacheProvider as default };
|
|
4
|
+
/**
|
|
5
|
+
* Built-in query parameter patterns excluded from cache keys.
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
export declare const DEFAULT_EXCLUDED_PARAMS: readonly ["utm_*", "fbclid", "gclid", "gbraid", "wbraid", "dclid", "msclkid", "twclid", "li_fat_id", "mc_cid", "mc_eid", "_ga", "_gl", "_hsenc", "_hsmi", "_ke", "oly_anon_id", "oly_enc_id", "rb_clickid", "s_cid", "vero_id", "wickedid", "yclid", "__s", "ref"];
|
|
9
|
+
/**
|
|
10
|
+
* Query string normalization settings for cache key generation.
|
|
11
|
+
*
|
|
12
|
+
* `include` and `exclude` are mutually exclusive.
|
|
13
|
+
*/
|
|
14
|
+
export interface QueryConfigInput {
|
|
15
|
+
/**
|
|
16
|
+
* Only these query parameter names are included in cache keys.
|
|
17
|
+
* @default undefined
|
|
18
|
+
*/
|
|
19
|
+
include?: string[];
|
|
20
|
+
/**
|
|
21
|
+
* Query parameter names or glob patterns excluded from cache keys.
|
|
22
|
+
* @default {@link DEFAULT_EXCLUDED_PARAMS}
|
|
23
|
+
*/
|
|
24
|
+
exclude?: string[];
|
|
25
|
+
/**
|
|
26
|
+
* Sorts query parameters before key generation for stable cache keys.
|
|
27
|
+
* @default true
|
|
28
|
+
*/
|
|
29
|
+
sort?: boolean;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Configuration for the Redis cache provider.
|
|
33
|
+
*/
|
|
34
|
+
interface RedisCacheProviderOptions {
|
|
35
|
+
/**
|
|
36
|
+
* Redis connection URL or runtime resolver for values unavailable at build time.
|
|
37
|
+
* @default undefined
|
|
38
|
+
*/
|
|
39
|
+
url?: string | (() => string | undefined);
|
|
40
|
+
/**
|
|
41
|
+
* Prefix used for all cache keys stored in Redis.
|
|
42
|
+
* @default "astro:cache"
|
|
43
|
+
*/
|
|
44
|
+
keyPrefix?: string;
|
|
45
|
+
/**
|
|
46
|
+
* Query string normalization rules used when building cache keys.
|
|
47
|
+
* @default undefined
|
|
48
|
+
*/
|
|
49
|
+
query?: QueryConfigInput;
|
|
50
|
+
/**
|
|
51
|
+
* Lock TTL in seconds for stale-while-revalidate background refresh.
|
|
52
|
+
* @default 30
|
|
53
|
+
*/
|
|
54
|
+
revalidateLockTtl?: number;
|
|
55
|
+
/**
|
|
56
|
+
* Additional `Vary` header names to ignore during cache key matching.
|
|
57
|
+
* `set-cookie` is always ignored.
|
|
58
|
+
*
|
|
59
|
+
* @default []
|
|
60
|
+
*/
|
|
61
|
+
ignoredVaryHeaders?: Iterable<string>;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Astro cache provider implementation with an explicit shutdown hook.
|
|
65
|
+
*/
|
|
66
|
+
interface RedisCacheProvider extends CacheProvider {
|
|
67
|
+
/** Closes the Redis client connection used by the provider instance. */
|
|
68
|
+
close(): Promise<void>;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Creates a Redis-backed cache provider for Astro route caching.
|
|
72
|
+
*/
|
|
73
|
+
declare function createRedisCacheProvider(config?: RedisCacheProviderOptions): RedisCacheProvider;
|
|
74
|
+
//# sourceMappingURL=runtime.d.ts.map
|
|
@@ -0,0 +1 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