Skip to content

Commit

Permalink
Docs for disabling cache, Wrangler disable updater, bump to 1.3.3
Browse files Browse the repository at this point in the history
  • Loading branch information
mrbbot committed Jul 26, 2021
1 parent 5c1dfba commit d8ea54d
Show file tree
Hide file tree
Showing 11 changed files with 78 additions and 27 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
# 🚧 Changelog

## 1.3.3

### Features

- Added an option to disable default and named caches. When disabled, the caches
will still be available in the sandbox, they just won't cache anything. Thanks
[@frandiox](https://github.com/frandiox) for the suggestion. See
[✨ Cache](https://miniflare.dev/cache.html#disabling) for more details.
- Added the corresponding `wrangler.toml` key for the `--disable-updater` flag:
`miniflare.disable_updater`

### Fixes

- Fixed the `package.json` file path the update checker checked against

## 1.3.2

### Features
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ Options:
-k, --kv KV namespace to bind [array]
--kv-persist Path to persist KV data to (omit path for default)
--cache-persist Path to persist cached data to (omit path for default)
--disable-cache Disable caching with default/named caches [boolean]
-s, --site Path to serve Workers Site files from [string]
--site-include Glob pattern of site files to serve [array]
--site-exclude Glob pattern of site files not to serve [array]
Expand Down
22 changes: 22 additions & 0 deletions docs/cache.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,25 @@ await cache.put(
res = await mf.dispatchFetch("http://localhost:8787");
console.log(await res.text()); // 2
```

## Disabling

Both default and named caches can be disabled with the `disableCache` option.
When disabled, the caches will still be available in the sandbox, they just
won't cache anything. This may be useful during development:

```shell
$ miniflare --disable-cache
```

```toml
# wrangler.toml
[miniflare]
disable_cache = true
```

```js
const mf = new Miniflare({
disableCache: true,
});
```
3 changes: 3 additions & 0 deletions docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ Options:
-k, --kv KV namespace to bind [array]
--kv-persist Path to persist KV data to (omit path for default)
--cache-persist Path to persist cached data to (omit path for default)
--disable-cache Disable caching with default/named caches [boolean]
-s, --site Path to serve Workers Site files from [string]
--site-include Glob pattern of site files to serve [array]
--site-exclude Glob pattern of site files not to serve [array]
Expand Down Expand Up @@ -235,13 +236,15 @@ globs = ["**/*.js"]
upstream = "https://miniflare.dev" ## --upstream
kv_persist = true ## --kv-persist
cache_persist = "./cache" ## --cache-persist
disable_cache = true ## --disable-cache
durable_objects_persist = true ## --do-persist
env_path = ".env.test" ## --env
host = "127.0.0.1" ## --host
port = 1337 ## --port
wasm_bindings = [ ## --wasm
{ name = "MODULE", path="module.wasm" }
]
disable_updater = true ## --disable-updater
https = true ## --https
https = "./cert_cache" ## --https ./cert_cache
[miniflare.https]
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "miniflare",
"version": "1.3.2",
"version": "1.3.3",
"description": "Fun, full-featured, fully-local simulator for Cloudflare Workers",
"keywords": [
"cloudflare",
Expand Down
46 changes: 24 additions & 22 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,29 +304,31 @@ if (module === require.main) {
const mf = new Miniflare(options);

mf.getOptions()
.then(async ({ host, port = defaultPort, processedHttps }) => {
const secure = processedHttps !== undefined;
(await mf.createServer(secure as any)).listen(port, host, async () => {
const protocol = secure ? "https" : "http";
mf.log.info(`Listening on ${host ?? ""}:${port}`);
if (host) {
mf.log.info(`- ${protocol}://${host}:${port}`);
} else {
for (const accessibleHost of getAccessibleHosts(true)) {
mf.log.info(`- ${protocol}://${accessibleHost}:${port}`);
.then(
async ({ host, port = defaultPort, processedHttps, disableUpdater }) => {
const secure = processedHttps !== undefined;
(await mf.createServer(secure as any)).listen(port, host, async () => {
const protocol = secure ? "https" : "http";
mf.log.info(`Listening on ${host ?? ""}:${port}`);
if (host) {
mf.log.info(`- ${protocol}://${host}:${port}`);
} else {
for (const accessibleHost of getAccessibleHosts(true)) {
mf.log.info(`- ${protocol}://${accessibleHost}:${port}`);
}
}
}

// Check for updates, ignoring errors (it's not that important)
if (options.disableUpdater) return;
try {
// Get currently installed package metadata
const pkgFile = path.join(__dirname, "..", "..", "package.json");
const pkg = JSON.parse(await fs.readFile(pkgFile, "utf8"));
const cachePath = envPaths(pkg.name).cache;
await updateCheck({ pkg, cachePath, log: mf.log });
} catch {}
});
})
// Check for updates, ignoring errors (it's not that important)
if (disableUpdater) return;
try {
// Get currently installed package metadata
const pkgFile = path.join(__dirname, "..", "package.json");
const pkg = JSON.parse(await fs.readFile(pkgFile, "utf8"));
const cachePath = envPaths(pkg.name).cache;
await updateCheck({ pkg, cachePath, log: mf.log });
} catch (e) {}
});
}
)
.catch((err) => mf.log.error(err));
}
2 changes: 1 addition & 1 deletion src/options/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export function logOptions(log: Log, options: ProcessedOptions): void {
"KV Namespaces": options.kvNamespaces,
"KV Persistence": options.kvPersist,
"Cache Persistence": options.cachePersist,
"Disable Cache": options.disableCache,
"Cache Disabled": options.disableCache,
"Workers Site Path": options.sitePath,
"Workers Site Include": options.siteIncludeRegexps,
// Only include excludeRegexps if there are no includeRegexps
Expand Down
4 changes: 4 additions & 0 deletions src/options/wrangler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ interface WranglerEnvironmentConfig {
upstream?: string;
kv_persist?: boolean | string;
cache_persist?: boolean | string;
disable_cache?: boolean;
durable_objects_persist?: boolean | string;
env_path?: string;
host?: string;
Expand All @@ -67,6 +68,7 @@ interface WranglerEnvironmentConfig {
passphrase?: string;
};
wasm_bindings?: { name: string; path: string }[];
disable_updater?: boolean;
};
}

Expand Down Expand Up @@ -159,6 +161,7 @@ export function getWranglerOptions(
upstream: config.miniflare?.upstream,
kvPersist: config.miniflare?.kv_persist,
cachePersist: config.miniflare?.cache_persist,
disableCache: config.miniflare?.disable_cache,
durableObjectsPersist: config.miniflare?.durable_objects_persist,
envPath: config.miniflare?.env_path,
host: config.miniflare?.host,
Expand All @@ -180,5 +183,6 @@ export function getWranglerOptions(
},
{} as Record<string, string>
),
disableUpdater: config.miniflare?.disable_updater,
};
}
2 changes: 1 addition & 1 deletion test/options/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ test("logOptions: logs all options", (t) => {
"- KV Namespaces: NAMESPACE1, NAMESPACE2",
"- KV Persistence: kv-data",
"- Cache Persistence: false",
"- Disable Cache: true",
"- Cache Disabled: true",
"- Workers Site Path: public",
"- Workers Site Include: regexp1, regexp2",
"- Durable Objects: OBJECT1, OBJECT2",
Expand Down
4 changes: 4 additions & 0 deletions test/options/wrangler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ test("getWranglerOptions: maps all options", (t) => {
upstream = "https://miniflare.dev"
kv_persist = true
cache_persist = "./cache"
disable_cache = true
durable_objects_persist = true
env_path = ".env.test"
host = "127.0.0.1"
Expand All @@ -106,6 +107,7 @@ test("getWranglerOptions: maps all options", (t) => {
wasm_bindings = [
{ name = "MODULE", path="module.wasm" }
]
disable_updater = true
`,
cwd
);
Expand All @@ -130,12 +132,14 @@ test("getWranglerOptions: maps all options", (t) => {
upstream: "https://miniflare.dev",
kvPersist: true,
cachePersist: "./cache",
disableCache: true,
durableObjectsPersist: true,
envPath: ".env.test",
host: "127.0.0.1",
port: 1337,
https: true,
wasmBindings: { MODULE: "module.wasm" },
disableUpdater: true,
});
});
test("getWranglerOptions: returns empty default options with empty file", (t) => {
Expand Down

0 comments on commit d8ea54d

Please sign in to comment.