11import path from "path" ;
22import { MiniflareError } from "../error" ;
3- import { Cache } from "../kv" ;
3+ import { Cache , NoOpCache } from "../kv" ;
44import { KVStorageFactory } from "../kv/helpers" ;
55import { Log } from "../log" ;
66import { ProcessedOptions } from "../options" ;
@@ -9,6 +9,8 @@ import { Context, Module } from "./module";
99const defaultPersistRoot = path . resolve ( ".mf" , "cache" ) ;
1010const defaultCacheName = "default" ;
1111
12+ const noopCache = new NoOpCache ( ) ;
13+
1214export class CacheModule extends Module {
1315 constructor (
1416 log : Log ,
@@ -22,7 +24,9 @@ export class CacheModule extends Module {
2224 }
2325
2426 buildSandbox ( options : ProcessedOptions ) : Context {
25- const defaultCache = this . getCache ( undefined , options . cachePersist ) ;
27+ const defaultCache = options . disableCache
28+ ? noopCache
29+ : this . getCache ( undefined , options . cachePersist ) ;
2630 return {
2731 caches : {
2832 default : defaultCache ,
@@ -32,7 +36,9 @@ export class CacheModule extends Module {
3236 `\"${ defaultCacheName } \" is a reserved cache name`
3337 ) ;
3438 }
35- return this . getCache ( name , options . cachePersist ) ;
39+ return options . disableCache
40+ ? noopCache
41+ : this . getCache ( name , options . cachePersist ) ;
3642 } ,
3743 } ,
3844 } ;
@@ -42,3 +48,5 @@ export class CacheModule extends Module {
4248 this . storageFactory . dispose ( ) ;
4349 }
4450}
51+
52+ export { Cache , NoOpCache } ;
0 commit comments