File tree Expand file tree Collapse file tree 2 files changed +14
-6
lines changed
Expand file tree Collapse file tree 2 files changed +14
-6
lines changed Original file line number Diff line number Diff line change @@ -247,10 +247,7 @@ module.exports = class CachePolicy {
247247 return false ;
248248 }
249249
250- if (
251- requestCC [ 'min-fresh' ] &&
252- this . timeToLive ( ) < 1000 * requestCC [ 'min-fresh' ]
253- ) {
250+ if ( requestCC [ 'min-fresh' ] && this . maxAge ( ) - this . age ( ) < toNumberOrZero ( requestCC [ 'min-fresh' ] ) ) {
254251 return false ;
255252 }
256253
@@ -455,9 +452,9 @@ module.exports = class CachePolicy {
455452 }
456453
457454 /**
458- * Up-to-date `max-age` value , in *milliseconds*.
455+ * Remaining time this cache entry may be useful for , in *milliseconds*.
459456 *
460- * Prefer this method over `maxAge()`.
457+ * Prefer this method over `maxAge()`, because it includes other factors .
461458 */
462459 timeToLive ( ) {
463460 const age = this . maxAge ( ) - this . age ( ) ;
Original file line number Diff line number Diff line change @@ -369,6 +369,17 @@ describe('okhttp tests', function() {
369369 ) ;
370370 } ) ;
371371
372+ it ( 'request min fresh with stale-while-revalidate' , function ( ) {
373+ const cache = new CachePolicy (
374+ { headers : { } } ,
375+ { headers : { 'cache-control' : 'max-age=60, stale-while-revalidate=100000' } } ,
376+ { shared : false }
377+ ) ;
378+
379+ assert ( ! cache . satisfiesWithoutRevalidation ( { headers : { 'cache-control' : 'min-fresh=120' } } ) ) ;
380+ assert ( cache . satisfiesWithoutRevalidation ( { headers : { 'cache-control' : 'min-fresh=10' } } ) ) ;
381+ } ) ;
382+
372383 it ( 'request max stale' , function ( ) {
373384 const cache = new CachePolicy (
374385 { headers : { } } ,
You can’t perform that action at this time.
0 commit comments