@nowarajs/elysia-cache 1.1.0 โ†’ 1.2.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/CHANGELOG.md CHANGED
@@ -1,38 +1,15 @@
1
1
 
2
- ## v1.1.0
2
+ ## v1.2.1
3
3
 
4
+ [compare changes](https://github.com/NowaraJS/elysia-cache/compare/v1.2.0...v1.2.1)
4
5
 
5
- ### ๐Ÿš€ Enhancements
6
+ ### ๐Ÿงน Refactors
6
7
 
7
- - **๐Ÿš€:** [Add generateCacheKey utility for request caching] ([a4a8fc5](https://github.com/NowaraJS/elysia-cache/commit/a4a8fc5))
8
- - **๐Ÿš€:** [Implement caching mechanism for request responses] ([f6b4c83](https://github.com/NowaraJS/elysia-cache/commit/f6b4c83))
8
+ - **๐Ÿงน:** [Rename storage to store in cache options] ([66faf70](https://github.com/NowaraJS/elysia-cache/commit/66faf70))
9
9
 
10
10
  ### ๐Ÿ“– Documentation
11
11
 
12
- - **๐Ÿ“–:** [Update README.md for improved structure and clarity] - Restructured the README.md to enhance navigation and readability. - Added sections for Installation, Usage, and Cache Configuration. - Included detailed examples for basic setup and Redis store setup. - Updated the Table of Contents for better accessibility to key sections. ([2c9b8b9](https://github.com/NowaraJS/elysia-cache/commit/2c9b8b9))
13
-
14
- ### ๐ŸŒŠ Types
15
-
16
- - **๐ŸŒŠ:** [Add CacheOptions interface for caching configuration] ([af0d3f8](https://github.com/NowaraJS/elysia-cache/commit/af0d3f8))
17
-
18
- ### ๐Ÿฆ‰ Chore
19
-
20
- - **๐Ÿฆ‰:** [Update contact email in issue template] ([85ea2d3](https://github.com/NowaraJS/elysia-cache/commit/85ea2d3))
21
- - **๐Ÿฆ‰:** [Remove npm-template-setup script] ([114b8ba](https://github.com/NowaraJS/elysia-cache/commit/114b8ba))
22
- - **๐Ÿฆ‰:** [Update copyright holder in LICENSE file] ([7834491](https://github.com/NowaraJS/elysia-cache/commit/7834491))
23
- - **๐Ÿฆ‰:** [Update contact email in Code of Conduct] ([2758b1e](https://github.com/NowaraJS/elysia-cache/commit/2758b1e))
24
- - **๐Ÿฆ‰:** [Update issue links in CONTRIBUTING.md] ([59146ac](https://github.com/NowaraJS/elysia-cache/commit/59146ac))
25
- - **๐Ÿฆ‰:** [Update links in SECURITY.md for accuracy] ([1df02a4](https://github.com/NowaraJS/elysia-cache/commit/1df02a4))
26
- - **๐Ÿฆ‰:** [Update package.json for project configuration] ([8cc0630](https://github.com/NowaraJS/elysia-cache/commit/8cc0630))
27
-
28
- ### ๐Ÿงช Tests
29
-
30
- - **๐Ÿงช:** [Add unit tests for generateCacheKey utility] ## Tests - Implemented unit tests for the `generateCacheKey` function. - Added tests for requests with and without bodies. - Verified that identical requests produce the same cache key. - Ensured different bodies generate different cache keys. ([43ae866](https://github.com/NowaraJS/elysia-cache/commit/43ae866))
31
- - **๐Ÿงช:** [Remove unused unit test file] ([ddd5fbc](https://github.com/NowaraJS/elysia-cache/commit/ddd5fbc))
32
-
33
- ### ๐Ÿค– CI
34
-
35
- - **๐Ÿค–:** [Remove bun-version specification in CI workflows] ## CI Changes - Removed the `bun-version` specification from the Setup Bun step in both job-integration-test.yml and job-unit-test.yml. ([ee5423d](https://github.com/NowaraJS/elysia-cache/commit/ee5423d))
12
+ - **๐Ÿ“–:** [Update CHANGELOG for version 1.2.0 release] ([e2bdc78](https://github.com/NowaraJS/elysia-cache/commit/e2bdc78))
36
13
 
37
14
  ### โค๏ธ Contributors
38
15
 
@@ -0,0 +1,306 @@
1
+ import { Elysia } from 'elysia';
2
+ import { MemoryStore } from '@nowarajs/kv-store/memory';
3
+ import type { CacheOptions } from './types/cacheOptions';
4
+ export declare const cache: ({ defaultTtl, prefix, store }?: CacheOptions) => Elysia<"", {
5
+ decorator: {};
6
+ store: {
7
+ kvStore: import("@nowarajs/kv-store/types").KvStore | MemoryStore;
8
+ _cacheKey: string;
9
+ };
10
+ derive: {};
11
+ resolve: {};
12
+ }, {
13
+ typebox: {};
14
+ error: {};
15
+ }, {
16
+ schema: {};
17
+ standaloneSchema: {};
18
+ macro: Partial<{
19
+ readonly isCached: number | boolean;
20
+ }>;
21
+ macroFn: {
22
+ readonly isCached: (enable: boolean | number) => {
23
+ afterHandle({ set, response, store }: {
24
+ body: unknown;
25
+ query: Record<string, string>;
26
+ params: Record<string, string>;
27
+ headers: Record<string, string | undefined>;
28
+ cookie: Record<string, import("elysia").Cookie<string | undefined>>;
29
+ server: import("elysia/universal/server").Server | null;
30
+ redirect: import("elysia").redirect;
31
+ set: {
32
+ headers: import("elysia").HTTPHeaders;
33
+ status?: number | keyof import("elysia").StatusMap;
34
+ redirect?: string;
35
+ cookie?: Record<string, import("elysia/cookies").ElysiaCookie>;
36
+ };
37
+ path: string;
38
+ route: string;
39
+ request: Request;
40
+ store: {
41
+ kvStore: import("@nowarajs/kv-store/types").KvStore | MemoryStore;
42
+ _cacheKey: string;
43
+ };
44
+ status: <const Code extends number | keyof import("elysia").StatusMap, const T = Code extends 301 | 302 | 303 | 307 | 308 | 100 | 101 | 102 | 103 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 300 | 304 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 421 | 422 | 423 | 424 | 425 | 426 | 428 | 429 | 431 | 451 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511 ? {
45
+ readonly 100: "Continue";
46
+ readonly 101: "Switching Protocols";
47
+ readonly 102: "Processing";
48
+ readonly 103: "Early Hints";
49
+ readonly 200: "OK";
50
+ readonly 201: "Created";
51
+ readonly 202: "Accepted";
52
+ readonly 203: "Non-Authoritative Information";
53
+ readonly 204: "No Content";
54
+ readonly 205: "Reset Content";
55
+ readonly 206: "Partial Content";
56
+ readonly 207: "Multi-Status";
57
+ readonly 208: "Already Reported";
58
+ readonly 300: "Multiple Choices";
59
+ readonly 301: "Moved Permanently";
60
+ readonly 302: "Found";
61
+ readonly 303: "See Other";
62
+ readonly 304: "Not Modified";
63
+ readonly 307: "Temporary Redirect";
64
+ readonly 308: "Permanent Redirect";
65
+ readonly 400: "Bad Request";
66
+ readonly 401: "Unauthorized";
67
+ readonly 402: "Payment Required";
68
+ readonly 403: "Forbidden";
69
+ readonly 404: "Not Found";
70
+ readonly 405: "Method Not Allowed";
71
+ readonly 406: "Not Acceptable";
72
+ readonly 407: "Proxy Authentication Required";
73
+ readonly 408: "Request Timeout";
74
+ readonly 409: "Conflict";
75
+ readonly 410: "Gone";
76
+ readonly 411: "Length Required";
77
+ readonly 412: "Precondition Failed";
78
+ readonly 413: "Payload Too Large";
79
+ readonly 414: "URI Too Long";
80
+ readonly 415: "Unsupported Media Type";
81
+ readonly 416: "Range Not Satisfiable";
82
+ readonly 417: "Expectation Failed";
83
+ readonly 418: "I'm a teapot";
84
+ readonly 421: "Misdirected Request";
85
+ readonly 422: "Unprocessable Content";
86
+ readonly 423: "Locked";
87
+ readonly 424: "Failed Dependency";
88
+ readonly 425: "Too Early";
89
+ readonly 426: "Upgrade Required";
90
+ readonly 428: "Precondition Required";
91
+ readonly 429: "Too Many Requests";
92
+ readonly 431: "Request Header Fields Too Large";
93
+ readonly 451: "Unavailable For Legal Reasons";
94
+ readonly 500: "Internal Server Error";
95
+ readonly 501: "Not Implemented";
96
+ readonly 502: "Bad Gateway";
97
+ readonly 503: "Service Unavailable";
98
+ readonly 504: "Gateway Timeout";
99
+ readonly 505: "HTTP Version Not Supported";
100
+ readonly 506: "Variant Also Negotiates";
101
+ readonly 507: "Insufficient Storage";
102
+ readonly 508: "Loop Detected";
103
+ readonly 510: "Not Extended";
104
+ readonly 511: "Network Authentication Required";
105
+ }[Code] : Code>(code: Code, response?: T) => import("elysia").ElysiaCustomStatusResponse<Code, T, Code extends "Continue" | "Switching Protocols" | "Processing" | "Early Hints" | "OK" | "Created" | "Accepted" | "Non-Authoritative Information" | "No Content" | "Reset Content" | "Partial Content" | "Multi-Status" | "Already Reported" | "Multiple Choices" | "Moved Permanently" | "Found" | "See Other" | "Not Modified" | "Temporary Redirect" | "Permanent Redirect" | "Bad Request" | "Unauthorized" | "Payment Required" | "Forbidden" | "Not Found" | "Method Not Allowed" | "Not Acceptable" | "Proxy Authentication Required" | "Request Timeout" | "Conflict" | "Gone" | "Length Required" | "Precondition Failed" | "Payload Too Large" | "URI Too Long" | "Unsupported Media Type" | "Range Not Satisfiable" | "Expectation Failed" | "I'm a teapot" | "Misdirected Request" | "Unprocessable Content" | "Locked" | "Failed Dependency" | "Too Early" | "Upgrade Required" | "Precondition Required" | "Too Many Requests" | "Request Header Fields Too Large" | "Unavailable For Legal Reasons" | "Internal Server Error" | "Not Implemented" | "Bad Gateway" | "Service Unavailable" | "Gateway Timeout" | "HTTP Version Not Supported" | "Variant Also Negotiates" | "Insufficient Storage" | "Loop Detected" | "Not Extended" | "Network Authentication Required" ? {
106
+ readonly Continue: 100;
107
+ readonly "Switching Protocols": 101;
108
+ readonly Processing: 102;
109
+ readonly "Early Hints": 103;
110
+ readonly OK: 200;
111
+ readonly Created: 201;
112
+ readonly Accepted: 202;
113
+ readonly "Non-Authoritative Information": 203;
114
+ readonly "No Content": 204;
115
+ readonly "Reset Content": 205;
116
+ readonly "Partial Content": 206;
117
+ readonly "Multi-Status": 207;
118
+ readonly "Already Reported": 208;
119
+ readonly "Multiple Choices": 300;
120
+ readonly "Moved Permanently": 301;
121
+ readonly Found: 302;
122
+ readonly "See Other": 303;
123
+ readonly "Not Modified": 304;
124
+ readonly "Temporary Redirect": 307;
125
+ readonly "Permanent Redirect": 308;
126
+ readonly "Bad Request": 400;
127
+ readonly Unauthorized: 401;
128
+ readonly "Payment Required": 402;
129
+ readonly Forbidden: 403;
130
+ readonly "Not Found": 404;
131
+ readonly "Method Not Allowed": 405;
132
+ readonly "Not Acceptable": 406;
133
+ readonly "Proxy Authentication Required": 407;
134
+ readonly "Request Timeout": 408;
135
+ readonly Conflict: 409;
136
+ readonly Gone: 410;
137
+ readonly "Length Required": 411;
138
+ readonly "Precondition Failed": 412;
139
+ readonly "Payload Too Large": 413;
140
+ readonly "URI Too Long": 414;
141
+ readonly "Unsupported Media Type": 415;
142
+ readonly "Range Not Satisfiable": 416;
143
+ readonly "Expectation Failed": 417;
144
+ readonly "I'm a teapot": 418;
145
+ readonly "Misdirected Request": 421;
146
+ readonly "Unprocessable Content": 422;
147
+ readonly Locked: 423;
148
+ readonly "Failed Dependency": 424;
149
+ readonly "Too Early": 425;
150
+ readonly "Upgrade Required": 426;
151
+ readonly "Precondition Required": 428;
152
+ readonly "Too Many Requests": 429;
153
+ readonly "Request Header Fields Too Large": 431;
154
+ readonly "Unavailable For Legal Reasons": 451;
155
+ readonly "Internal Server Error": 500;
156
+ readonly "Not Implemented": 501;
157
+ readonly "Bad Gateway": 502;
158
+ readonly "Service Unavailable": 503;
159
+ readonly "Gateway Timeout": 504;
160
+ readonly "HTTP Version Not Supported": 505;
161
+ readonly "Variant Also Negotiates": 506;
162
+ readonly "Insufficient Storage": 507;
163
+ readonly "Loop Detected": 508;
164
+ readonly "Not Extended": 510;
165
+ readonly "Network Authentication Required": 511;
166
+ }[Code] : Code>;
167
+ error: <const Code extends number | keyof import("elysia").StatusMap, const T = Code extends 301 | 302 | 303 | 307 | 308 | 100 | 101 | 102 | 103 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 300 | 304 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 421 | 422 | 423 | 424 | 425 | 426 | 428 | 429 | 431 | 451 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511 ? {
168
+ readonly 100: "Continue";
169
+ readonly 101: "Switching Protocols";
170
+ readonly 102: "Processing";
171
+ readonly 103: "Early Hints";
172
+ readonly 200: "OK";
173
+ readonly 201: "Created";
174
+ readonly 202: "Accepted";
175
+ readonly 203: "Non-Authoritative Information";
176
+ readonly 204: "No Content";
177
+ readonly 205: "Reset Content";
178
+ readonly 206: "Partial Content";
179
+ readonly 207: "Multi-Status";
180
+ readonly 208: "Already Reported";
181
+ readonly 300: "Multiple Choices";
182
+ readonly 301: "Moved Permanently";
183
+ readonly 302: "Found";
184
+ readonly 303: "See Other";
185
+ readonly 304: "Not Modified";
186
+ readonly 307: "Temporary Redirect";
187
+ readonly 308: "Permanent Redirect";
188
+ readonly 400: "Bad Request";
189
+ readonly 401: "Unauthorized";
190
+ readonly 402: "Payment Required";
191
+ readonly 403: "Forbidden";
192
+ readonly 404: "Not Found";
193
+ readonly 405: "Method Not Allowed";
194
+ readonly 406: "Not Acceptable";
195
+ readonly 407: "Proxy Authentication Required";
196
+ readonly 408: "Request Timeout";
197
+ readonly 409: "Conflict";
198
+ readonly 410: "Gone";
199
+ readonly 411: "Length Required";
200
+ readonly 412: "Precondition Failed";
201
+ readonly 413: "Payload Too Large";
202
+ readonly 414: "URI Too Long";
203
+ readonly 415: "Unsupported Media Type";
204
+ readonly 416: "Range Not Satisfiable";
205
+ readonly 417: "Expectation Failed";
206
+ readonly 418: "I'm a teapot";
207
+ readonly 421: "Misdirected Request";
208
+ readonly 422: "Unprocessable Content";
209
+ readonly 423: "Locked";
210
+ readonly 424: "Failed Dependency";
211
+ readonly 425: "Too Early";
212
+ readonly 426: "Upgrade Required";
213
+ readonly 428: "Precondition Required";
214
+ readonly 429: "Too Many Requests";
215
+ readonly 431: "Request Header Fields Too Large";
216
+ readonly 451: "Unavailable For Legal Reasons";
217
+ readonly 500: "Internal Server Error";
218
+ readonly 501: "Not Implemented";
219
+ readonly 502: "Bad Gateway";
220
+ readonly 503: "Service Unavailable";
221
+ readonly 504: "Gateway Timeout";
222
+ readonly 505: "HTTP Version Not Supported";
223
+ readonly 506: "Variant Also Negotiates";
224
+ readonly 507: "Insufficient Storage";
225
+ readonly 508: "Loop Detected";
226
+ readonly 510: "Not Extended";
227
+ readonly 511: "Network Authentication Required";
228
+ }[Code] : Code>(code: Code, response?: T) => import("elysia").ElysiaCustomStatusResponse<Code, T, Code extends "Continue" | "Switching Protocols" | "Processing" | "Early Hints" | "OK" | "Created" | "Accepted" | "Non-Authoritative Information" | "No Content" | "Reset Content" | "Partial Content" | "Multi-Status" | "Already Reported" | "Multiple Choices" | "Moved Permanently" | "Found" | "See Other" | "Not Modified" | "Temporary Redirect" | "Permanent Redirect" | "Bad Request" | "Unauthorized" | "Payment Required" | "Forbidden" | "Not Found" | "Method Not Allowed" | "Not Acceptable" | "Proxy Authentication Required" | "Request Timeout" | "Conflict" | "Gone" | "Length Required" | "Precondition Failed" | "Payload Too Large" | "URI Too Long" | "Unsupported Media Type" | "Range Not Satisfiable" | "Expectation Failed" | "I'm a teapot" | "Misdirected Request" | "Unprocessable Content" | "Locked" | "Failed Dependency" | "Too Early" | "Upgrade Required" | "Precondition Required" | "Too Many Requests" | "Request Header Fields Too Large" | "Unavailable For Legal Reasons" | "Internal Server Error" | "Not Implemented" | "Bad Gateway" | "Service Unavailable" | "Gateway Timeout" | "HTTP Version Not Supported" | "Variant Also Negotiates" | "Insufficient Storage" | "Loop Detected" | "Not Extended" | "Network Authentication Required" ? {
229
+ readonly Continue: 100;
230
+ readonly "Switching Protocols": 101;
231
+ readonly Processing: 102;
232
+ readonly "Early Hints": 103;
233
+ readonly OK: 200;
234
+ readonly Created: 201;
235
+ readonly Accepted: 202;
236
+ readonly "Non-Authoritative Information": 203;
237
+ readonly "No Content": 204;
238
+ readonly "Reset Content": 205;
239
+ readonly "Partial Content": 206;
240
+ readonly "Multi-Status": 207;
241
+ readonly "Already Reported": 208;
242
+ readonly "Multiple Choices": 300;
243
+ readonly "Moved Permanently": 301;
244
+ readonly Found: 302;
245
+ readonly "See Other": 303;
246
+ readonly "Not Modified": 304;
247
+ readonly "Temporary Redirect": 307;
248
+ readonly "Permanent Redirect": 308;
249
+ readonly "Bad Request": 400;
250
+ readonly Unauthorized: 401;
251
+ readonly "Payment Required": 402;
252
+ readonly Forbidden: 403;
253
+ readonly "Not Found": 404;
254
+ readonly "Method Not Allowed": 405;
255
+ readonly "Not Acceptable": 406;
256
+ readonly "Proxy Authentication Required": 407;
257
+ readonly "Request Timeout": 408;
258
+ readonly Conflict: 409;
259
+ readonly Gone: 410;
260
+ readonly "Length Required": 411;
261
+ readonly "Precondition Failed": 412;
262
+ readonly "Payload Too Large": 413;
263
+ readonly "URI Too Long": 414;
264
+ readonly "Unsupported Media Type": 415;
265
+ readonly "Range Not Satisfiable": 416;
266
+ readonly "Expectation Failed": 417;
267
+ readonly "I'm a teapot": 418;
268
+ readonly "Misdirected Request": 421;
269
+ readonly "Unprocessable Content": 422;
270
+ readonly Locked: 423;
271
+ readonly "Failed Dependency": 424;
272
+ readonly "Too Early": 425;
273
+ readonly "Upgrade Required": 426;
274
+ readonly "Precondition Required": 428;
275
+ readonly "Too Many Requests": 429;
276
+ readonly "Request Header Fields Too Large": 431;
277
+ readonly "Unavailable For Legal Reasons": 451;
278
+ readonly "Internal Server Error": 500;
279
+ readonly "Not Implemented": 501;
280
+ readonly "Bad Gateway": 502;
281
+ readonly "Service Unavailable": 503;
282
+ readonly "Gateway Timeout": 504;
283
+ readonly "HTTP Version Not Supported": 505;
284
+ readonly "Variant Also Negotiates": 506;
285
+ readonly "Insufficient Storage": 507;
286
+ readonly "Loop Detected": 508;
287
+ readonly "Not Extended": 510;
288
+ readonly "Network Authentication Required": 511;
289
+ }[Code] : Code>;
290
+ } & {
291
+ response: unknown;
292
+ }): Promise<void>;
293
+ };
294
+ };
295
+ parser: {};
296
+ }, {}, {
297
+ derive: {};
298
+ resolve: {};
299
+ schema: {};
300
+ standaloneSchema: {};
301
+ }, {
302
+ derive: {};
303
+ resolve: {};
304
+ schema: {};
305
+ standaloneSchema: {};
306
+ }>;
@@ -0,0 +1,28 @@
1
+ // source/utils/generateCacheKey.ts
2
+ var _calculateBodyHash = async (body, hasher) => {
3
+ if (!body)
4
+ return;
5
+ const reader = body.getReader();
6
+ try {
7
+ while (true) {
8
+ const { done, value } = await reader.read();
9
+ if (done)
10
+ break;
11
+ if (value)
12
+ hasher.update(new Uint8Array(value));
13
+ }
14
+ } finally {
15
+ reader.releaseLock();
16
+ }
17
+ };
18
+ var generateCacheKey = async (request) => {
19
+ const { method, url, headers } = request;
20
+ const hasher = new Bun.CryptoHasher("sha256");
21
+ hasher.update(method);
22
+ hasher.update(url);
23
+ hasher.update(JSON.stringify(headers));
24
+ await _calculateBodyHash(request.body, hasher);
25
+ return hasher.digest("hex");
26
+ };
27
+
28
+ export { generateCacheKey };
package/dist/index.d.ts CHANGED
@@ -1 +1 @@
1
- export {};
1
+ export { cache } from './cache';
package/dist/index.js CHANGED
@@ -1,6 +1,42 @@
1
1
  // @bun
2
- // source/index.ts
3
- var source_default = undefined;
2
+ import {
3
+ generateCacheKey
4
+ } from "./chunk-1tq91npe.js";
5
+
6
+ // source/cache.ts
7
+ import { Elysia } from "elysia";
8
+ import { MemoryStore } from "@nowarajs/kv-store/memory";
9
+ var cache = ({
10
+ defaultTtl = 60,
11
+ prefix = "",
12
+ store = ":memory:"
13
+ } = {}) => new Elysia().state("kvStore", store === ":memory:" ? new MemoryStore : store).state("_cacheKey", "").onRequest(async ({ request, store: store2, set }) => {
14
+ const cacheKey = await generateCacheKey(request.clone());
15
+ const cachedResponse = await store2.kvStore.get(`${prefix}${cacheKey}`);
16
+ store2._cacheKey = cacheKey;
17
+ if (cachedResponse) {
18
+ set.headers["Cache-Control"] = `max-age=${defaultTtl}, public`;
19
+ set.headers["X-Cache"] = "HIT";
20
+ set.headers["ETag"] = `"${prefix}${cacheKey}"`;
21
+ return cachedResponse;
22
+ }
23
+ return;
24
+ }).macro({
25
+ isCached: (enable) => {
26
+ const ttl = typeof enable === "number" ? enable : enable ? defaultTtl : 0;
27
+ return {
28
+ async afterHandle({ set, response, store: store2 }) {
29
+ const cacheKey = store2._cacheKey;
30
+ const now = new Date;
31
+ set.headers["Cache-Control"] = `max-age=${ttl}, public`;
32
+ set.headers["ETag"] = `"${prefix}${cacheKey}"`;
33
+ set.headers["Last-Modified"] = now.toUTCString();
34
+ set.headers["Expires"] = new Date(now.getTime() + ttl * 1000).toUTCString();
35
+ await store2.kvStore.set(`${prefix}${cacheKey}`, response, ttl);
36
+ }
37
+ };
38
+ }
39
+ });
4
40
  export {
5
- source_default as default
41
+ cache
6
42
  };
@@ -0,0 +1,21 @@
1
+ import type { KvStore } from '@nowarajs/kv-store/types';
2
+ export interface CacheOptions {
3
+ /**
4
+ * Default TTL in seconds
5
+ *
6
+ * @defaultValue 60
7
+ */
8
+ defaultTtl?: number;
9
+ /**
10
+ * Cache key prefix
11
+ *
12
+ * @defaultValue ''
13
+ */
14
+ prefix?: string;
15
+ /**
16
+ * Storage backend
17
+ *
18
+ * @defaultValue ':memory:'
19
+ */
20
+ store?: ':memory:' | KvStore;
21
+ }
@@ -1 +1 @@
1
- export {};
1
+ export type { CacheOptions } from './cacheOptions';
@@ -1,6 +1 @@
1
1
  // @bun
2
- // source/types/index.ts
3
- var types_default = undefined;
4
- export {
5
- types_default as default
6
- };
@@ -0,0 +1,5 @@
1
+ import type { Request } from 'undici-types';
2
+ /**
3
+ * Generates a cache key from a request
4
+ */
5
+ export declare const generateCacheKey: (request: Request) => Promise<string>;
@@ -1 +1 @@
1
- export {};
1
+ export { generateCacheKey } from './generateCacheKey';
@@ -1,6 +1,7 @@
1
1
  // @bun
2
- // source/utils/index.ts
3
- var utils_default = undefined;
2
+ import {
3
+ generateCacheKey
4
+ } from "../chunk-1tq91npe.js";
4
5
  export {
5
- utils_default as default
6
+ generateCacheKey
6
7
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nowarajs/elysia-cache",
3
- "version": "1.1.0",
3
+ "version": "1.2.1",
4
4
  "author": "NowaraJS",
5
5
  "description": "A template to create a bun package.",
6
6
  "type": "module",
@@ -39,7 +39,6 @@
39
39
  "elysia": "^1.3.20"
40
40
  },
41
41
  "exports": {
42
- "./enums": "./dist/enums/index.js",
43
42
  "./types": "./dist/types/index.js",
44
43
  "./utils": "./dist/utils/index.js",
45
44
  ".": "./dist/index.js"
@@ -1 +0,0 @@
1
- export {};
@@ -1,6 +0,0 @@
1
- // @bun
2
- // source/enums/index.ts
3
- var enums_default = undefined;
4
- export {
5
- enums_default as default
6
- };