@@ -123,6 +123,7 @@ void requireValidHeaderValue(kj::StringPtr value) {
123123Request::CacheMode getCacheModeFromName (kj::StringPtr value) {
124124 if (value == " no-store" ) return Request::CacheMode::NOSTORE;
125125 if (value == " no-cache" ) return Request::CacheMode::NOCACHE;
126+ if (value == " reload" ) return Request::CacheMode::RELOAD;
126127 JSG_FAIL_REQUIRE (TypeError, kj::str (" Unsupported cache mode: " , value));
127128}
128129
@@ -134,6 +135,8 @@ jsg::Optional<kj::StringPtr> getCacheModeName(Request::CacheMode mode) {
134135 return " no-cache" _kj;
135136 case (Request::CacheMode::NOSTORE):
136137 return " no-store" _kj;
138+ case (Request::CacheMode::RELOAD):
139+ return " reload" _kj;
137140 }
138141 KJ_UNREACHABLE;
139142}
@@ -1241,19 +1244,20 @@ kj::Maybe<kj::String> Request::serializeCfBlobJson(jsg::Lock& js) {
12411244 }
12421245 auto obj = KJ_ASSERT_NONNULL (clone.get (js));
12431246
1244- int ttl = 2 ;
1247+ constexpr int NOCACHE_TTL = - 1 ;
12451248 switch (cacheMode) {
12461249 case CacheMode::NOSTORE:
1247- ttl = -1 ;
1248- obj.set (js, " cacheLevel" , js.str (" bypass" _kjc));
12491250 if (obj.has (js, " cacheTtl" )) {
12501251 jsg::JsValue oldTtl = obj.get (js, " cacheTtl" );
1251- JSG_REQUIRE (oldTtl == js.num (ttl ), TypeError,
1252+ JSG_REQUIRE (oldTtl == js.num (NOCACHE_TTL ), TypeError,
12521253 kj::str (" CacheTtl: " , oldTtl, " , is not compatible with cache: " ,
12531254 getCacheModeName (cacheMode).orDefault (" none" _kj), " header." ));
12541255 } else {
1255- obj.set (js, " cacheTtl" , js.num (ttl ));
1256+ obj.set (js, " cacheTtl" , js.num (NOCACHE_TTL ));
12561257 }
1258+ KJ_FALLTHROUGH;
1259+ case CacheMode::RELOAD:
1260+ obj.set (js, " cacheLevel" , js.str (" bypass" _kjc));
12571261 break ;
12581262 case CacheMode::NOCACHE:
12591263 obj.set (js, " cacheForceRevalidate" , js.boolean (true ));
@@ -1274,10 +1278,12 @@ void RequestInitializerDict::validate(jsg::Lock& js) {
12741278 // Validate that the cache type is valid
12751279 auto cacheMode = getCacheModeFromName (c);
12761280
1277- if (!FeatureFlags::get (js).getCacheNoCache ()) {
1278- JSG_REQUIRE (cacheMode != Request::CacheMode::NOCACHE, TypeError,
1279- kj::str (" Unsupported cache mode: " , c));
1280- }
1281+ bool invalidNoCache =
1282+ !FeatureFlags::get (js).getCacheNoCache () && (cacheMode == Request::CacheMode::NOCACHE);
1283+ bool invalidReload =
1284+ !FeatureFlags::get (js).getCacheReload () && (cacheMode == Request::CacheMode::RELOAD);
1285+ JSG_REQUIRE (
1286+ !invalidNoCache && !invalidReload, TypeError, kj::str (" Unsupported cache mode: " , c));
12811287 }
12821288
12831289 KJ_IF_SOME (e, encodeResponseBody) {
@@ -1901,11 +1907,12 @@ jsg::Promise<jsg::Ref<Response>> fetchImplNoOutputLock(jsg::Lock& js,
19011907 jsRequest->shallowCopyHeadersTo (headers);
19021908
19031909 // If the jsRequest has a CacheMode, we need to handle that here.
1904- // Currently, the only cache mode we support is undefined and no-store (behind an autogate),
1905- // but we will soon support no-cache.
1910+ // Currently, the only cache mode we support is undefined and no-store, no-cache, and reload
19061911 auto headerIds = ioContext.getHeaderIds ();
19071912 const auto cacheMode = jsRequest->getCacheMode ();
19081913 switch (cacheMode) {
1914+ case Request::CacheMode::RELOAD:
1915+ KJ_FALLTHROUGH;
19091916 case Request::CacheMode::NOSTORE:
19101917 KJ_FALLTHROUGH;
19111918 case Request::CacheMode::NOCACHE:
0 commit comments