|
1 | 1 | import assert from "assert"; |
2 | 2 | import { URL } from "url"; |
3 | 3 | import { Cache, CacheError, CachedMeta } from "@miniflare/cache"; |
4 | | -import { Request, RequestInitCfProperties, Response } from "@miniflare/core"; |
| 4 | +import { Request, Response } from "@miniflare/core"; |
5 | 5 | import { |
6 | 6 | EXTERNAL_SUBREQUEST_LIMIT_BUNDLED, |
7 | 7 | RequestContext, |
@@ -147,59 +147,6 @@ test("Cache: respects cache key", async (t) => { |
147 | 147 | t.is(await match1?.text(), "value1"); |
148 | 148 | t.is(await match2?.text(), "value2"); |
149 | 149 | }); |
150 | | -test("Cache: put respects cf cacheTtl", async (t) => { |
151 | | - const { clock, cache } = t.context; |
152 | | - await cache.put( |
153 | | - new Request("http://localhost/test", { cf: { cacheTtl: 1 } }), |
154 | | - new BaseResponse("value") |
155 | | - ); |
156 | | - t.not(await cache.match("http://localhost/test"), undefined); |
157 | | - clock.timestamp += 500; |
158 | | - t.not(await cache.match("http://localhost/test"), undefined); |
159 | | - clock.timestamp += 500; |
160 | | - t.is(await cache.match("http://localhost/test"), undefined); |
161 | | -}); |
162 | | -test("Cache: put respects cf cacheTtlByStatus", async (t) => { |
163 | | - const { clock, cache } = t.context; |
164 | | - const cf: RequestInitCfProperties = { |
165 | | - cacheTtlByStatus: { "200-299": 2, "? :D": 99, "404": 1, "500-599": 0 }, |
166 | | - }; |
167 | | - const headers = { "Cache-Control": "max-age=5" }; |
168 | | - const req200 = new Request("http://localhost/200", { cf }); |
169 | | - const req201 = new Request("http://localhost/201", { cf }); |
170 | | - const req302 = new Request("http://localhost/302", { cf }); |
171 | | - const req404 = new Request("http://localhost/404", { cf }); |
172 | | - const req599 = new Request("http://localhost/599", { cf }); |
173 | | - await cache.put(req200, new BaseResponse(null, { status: 200, headers })); |
174 | | - await cache.put(req201, new BaseResponse(null, { status: 201, headers })); |
175 | | - await cache.put(req302, new BaseResponse(null, { status: 302, headers })); |
176 | | - await cache.put(req404, new BaseResponse(null, { status: 404, headers })); |
177 | | - await cache.put(req599, new BaseResponse(null, { status: 599, headers })); |
178 | | - |
179 | | - // Check all but 5xx responses cached |
180 | | - t.not(await cache.match("http://localhost/200"), undefined); |
181 | | - t.not(await cache.match("http://localhost/201"), undefined); |
182 | | - t.not(await cache.match("http://localhost/302"), undefined); |
183 | | - t.not(await cache.match("http://localhost/404"), undefined); |
184 | | - t.is(await cache.match("http://localhost/599"), undefined); |
185 | | - |
186 | | - // Check 404 response expires after 1 second |
187 | | - clock.timestamp += 1000; |
188 | | - t.not(await cache.match("http://localhost/200"), undefined); |
189 | | - t.not(await cache.match("http://localhost/201"), undefined); |
190 | | - t.not(await cache.match("http://localhost/302"), undefined); |
191 | | - t.is(await cache.match("http://localhost/404"), undefined); |
192 | | - |
193 | | - // Check 2xx responses expire after 2 seconds |
194 | | - clock.timestamp += 1000; |
195 | | - t.is(await cache.match("http://localhost/200"), undefined); |
196 | | - t.is(await cache.match("http://localhost/201"), undefined); |
197 | | - t.not(await cache.match("http://localhost/302"), undefined); |
198 | | - |
199 | | - // Check 302 response expires after 5 seconds |
200 | | - clock.timestamp += 3000; |
201 | | - t.is(await cache.match("http://localhost/302"), undefined); |
202 | | -}); |
203 | 150 |
|
204 | 151 | test("Cache: put increments subrequest count", async (t) => { |
205 | 152 | const { cache } = t.context; |
|
0 commit comments