MCPcopy Index your code
hub / github.com/angular/angular / canUseOrCacheRequest

Function canUseOrCacheRequest

packages/common/http/src/transfer_cache.ts:128–152  ·  view source on GitHub ↗
(req: HttpRequest<unknown>, options: CacheOptions)

Source from the content-addressed store, hash-verified

126const ALLOWED_METHODS = ['GET', 'HEAD'];
127
128function canUseOrCacheRequest(req: HttpRequest<unknown>, options: CacheOptions): boolean {
129 const {isCacheActive, ...globalOptions} = options;
130 const {transferCache: requestOptions, method: requestMethod} = req;
131
132 if (
133 !isCacheActive ||
134 requestOptions === false ||
135 // Do not cache requests sent with credentials.
136 hasOutgoingCredentials(req) ||
137 // POST requests are allowed either globally or at request level
138 (requestMethod === 'POST' && !globalOptions.includePostRequests && !requestOptions) ||
139 (requestMethod !== 'POST' && !ALLOWED_METHODS.includes(requestMethod)) ||
140 // Do not cache requests with authentication or cookie headers unless explicitly enabled.
141 (!globalOptions.includeRequestsWithAuthHeaders && hasAuthHeaders(req)) ||
142 // Do not cache requests that explicitly forbid caching via Cache-Control
143 // or Fetch API cache mode.
144 hasUncacheableCacheControl(req.headers) ||
145 isNonCacheableRequest(req.cache) ||
146 globalOptions.filter?.(req) === false
147 ) {
148 return false;
149 }
150
151 return true;
152}
153
154function getHeadersToInclude(
155 options: CacheOptions,

Callers 2

retrieveStateFromCacheFunction · 0.85

Calls 5

hasOutgoingCredentialsFunction · 0.85
hasAuthHeadersFunction · 0.85
isNonCacheableRequestFunction · 0.85
filterMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…