@miniflare/cache
Advanced tools
Comparing version 2.0.0-rc.1 to 2.0.0-rc.2
@@ -31,3 +31,3 @@ import { Awaitable } from '@miniflare/shared'; | ||
export declare type CacheErrorCode = "ERR_RESERVED"; | ||
export declare type CacheErrorCode = "ERR_RESERVED" | "ERR_DESERIALIZATION"; | ||
@@ -34,0 +34,0 @@ export declare interface CacheInterface { |
@@ -31,2 +31,9 @@ var __defProp = Object.defineProperty; | ||
} from "undici"; | ||
// packages/cache/src/error.ts | ||
import { MiniflareError } from "@miniflare/shared"; | ||
var CacheError = class extends MiniflareError { | ||
}; | ||
// packages/cache/src/cache.ts | ||
function normaliseRequest(req) { | ||
@@ -151,6 +158,9 @@ return req instanceof Request || req instanceof BaseRequest ? req : new Request(req); | ||
return; | ||
const headers = new Headers(cached.metadata?.headers); | ||
if (!cached.metadata) { | ||
throw new CacheError("ERR_DESERIALIZATION", "Unable to deserialize stored cached data due to missing metadata.\nThe cached data storage format changed in Miniflare 2. You cannot load cached data created with Miniflare 1 and must delete it."); | ||
} | ||
const headers = new Headers(cached.metadata.headers); | ||
headers.set("CF-Cache-Status", "HIT"); | ||
let res = new Response(cached.value, { | ||
status: cached.metadata?.status, | ||
status: cached.metadata.status, | ||
headers | ||
@@ -190,6 +200,6 @@ }); | ||
import { | ||
MiniflareError, | ||
Option, | ||
OptionType, | ||
Plugin | ||
Plugin, | ||
resolveStoragePersist | ||
} from "@miniflare/shared"; | ||
@@ -199,4 +209,2 @@ var DEFAULT_CACHE_NAME = "default"; | ||
var NOOP_CACHE = new NoOpCache(); | ||
var CacheError = class extends MiniflareError { | ||
}; | ||
var CacheStorage = class { | ||
@@ -256,3 +264,8 @@ #options; | ||
setup(storageFactory) { | ||
this.#caches = new CacheStorage(this, this.ctx.log, storageFactory, this.ctx.compat.isEnabled("formdata_parser_supports_files")); | ||
const persist = resolveStoragePersist(this.ctx.rootPath, this.cachePersist); | ||
this.#caches = new CacheStorage({ | ||
cache: this.cache, | ||
cachePersist: persist, | ||
cacheWarnUsage: this.cacheWarnUsage | ||
}, this.ctx.log, storageFactory, this.ctx.compat.isEnabled("formdata_parser_supports_files")); | ||
return { globals: { caches: this.#caches } }; | ||
@@ -259,0 +272,0 @@ } |
{ | ||
"name": "@miniflare/cache", | ||
"version": "2.0.0-rc.1", | ||
"version": "2.0.0-rc.2", | ||
"description": "Cache module for Miniflare: a fun, full-featured, fully-local simulator for Cloudflare Workers", | ||
@@ -39,12 +39,12 @@ "keywords": [ | ||
"dependencies": { | ||
"@miniflare/core": "2.0.0-rc.1", | ||
"@miniflare/shared": "2.0.0-rc.1", | ||
"@miniflare/core": "2.0.0-rc.2", | ||
"@miniflare/shared": "2.0.0-rc.2", | ||
"http-cache-semantics": "^4.1.0", | ||
"undici": "^4.9.3" | ||
"undici": "^4.10.2" | ||
}, | ||
"devDependencies": { | ||
"@miniflare/shared-test": "2.0.0-rc.1", | ||
"@miniflare/web-sockets": "2.0.0-rc.1", | ||
"@miniflare/shared-test": "2.0.0-rc.2", | ||
"@miniflare/web-sockets": "2.0.0-rc.2", | ||
"@types/http-cache-semantics": "^4.0.1" | ||
} | ||
} |
# `@miniflare/cache` | ||
Cache module for [Miniflare](https://github.com/cloudflare/miniflare): a fun, | ||
full-featured, fully-local simulator for Cloudflare Workers | ||
full-featured, fully-local simulator for Cloudflare Workers. See | ||
[✨ Cache](https://miniflare.dev/cache.html) for more details. | ||
## Example | ||
```js | ||
import { Cache } from "@miniflare/cache"; | ||
import { Response } from "@miniflare/core"; | ||
import { MemoryStorage } from "@miniflare/storage-memory"; | ||
const cache = new Cache(new MemoryStorage()); | ||
const key = "http://localhost"; | ||
const res = new Response("body", { | ||
headers: { "Cache-Control": "max-age=3600" }, | ||
}); | ||
await cache.put(key, res); | ||
const cachedRes = await cache.match(key); | ||
console.log(await cachedRes.text()); // body | ||
``` |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
18275
359
25
+ Added@miniflare/core@2.0.0-rc.2(transitive)
+ Added@miniflare/shared@2.0.0-rc.2(transitive)
- Removed@miniflare/core@2.0.0-rc.1(transitive)
- Removed@miniflare/shared@2.0.0-rc.1(transitive)
Updated@miniflare/core@2.0.0-rc.2
Updated@miniflare/shared@2.0.0-rc.2
Updatedundici@^4.10.2