refine outbound request caching
This commit is contained in:
@@ -103,7 +103,7 @@ export function create_outbound_http_provider(conf: OutboundHttpConfig, logger:
|
||||
if (cached) {
|
||||
const revalidation = response_cache.determine_revalidation_needed(cached);
|
||||
|
||||
if (! revalidation.must_revalidate) {
|
||||
if (! revalidation.should_revalidate) {
|
||||
log.info('serving request from cache (no revalidation required)');
|
||||
result.status = cached.status;
|
||||
result.body = cached.body;
|
||||
@@ -111,6 +111,10 @@ export function create_outbound_http_provider(conf: OutboundHttpConfig, logger:
|
||||
return Promise.resolve(result);
|
||||
}
|
||||
|
||||
// if (! revalidation.must_revalidate) {
|
||||
// // todo: lazy revalidation option
|
||||
// }
|
||||
|
||||
log.info('cached response found, but requires revalidation');
|
||||
Object.assign(req_headers, revalidation.headers);
|
||||
}
|
||||
|
||||
@@ -7,6 +7,8 @@ import { parse_cache_headers, ParsedCacheHeaders } from './parse-cache-headers';
|
||||
import type { HttpURL } from '../utilities/types';
|
||||
import type { HttpResult } from './outbound';
|
||||
|
||||
// todo: second implementation that stores to disk / db
|
||||
|
||||
export interface RequestCacheConfig {
|
||||
// todo: support for configurable limits:
|
||||
max_records?: number; // max number of cached responses
|
||||
@@ -67,6 +69,7 @@ export function create_request_cache_provider(conf: RequestCacheConfig, logger:
|
||||
const { cache_control, etag, date, last_modified } = cached.cache_info;
|
||||
|
||||
const must_revalidate = Boolean(cache_control?.must_revalidate || cache_control?.no_cache);
|
||||
const should_revalidate = must_revalidate || cached.is_stale;
|
||||
const headers: OutgoingHttpHeaders = { };
|
||||
|
||||
if (etag) {
|
||||
@@ -83,6 +86,7 @@ export function create_request_cache_provider(conf: RequestCacheConfig, logger:
|
||||
|
||||
return {
|
||||
must_revalidate,
|
||||
should_revalidate,
|
||||
headers,
|
||||
};
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user