Skip to content

Commit

Permalink
feat(cache): Relax requirements for cacheable response headers (#34134)
Browse files Browse the repository at this point in the history
  • Loading branch information
zharinov authored Feb 10, 2025
1 parent 0875ee9 commit b5ae2f5
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 27 deletions.
6 changes: 3 additions & 3 deletions lib/modules/platform/bitbucket/pr-cache.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ describe('modules/platform/bitbucket/pr-cache', () => {
},
]);
expect(cache).toEqual({
httpCache: {},
httpCache: expect.toBeNonEmptyObject(),
platform: {
bitbucket: {
pullRequestsCache: {
Expand Down Expand Up @@ -123,7 +123,7 @@ describe('modules/platform/bitbucket/pr-cache', () => {
},
]);
expect(cache).toEqual({
httpCache: {},
httpCache: expect.toBeNonEmptyObject(),
platform: {
bitbucket: {
pullRequestsCache: {
Expand Down Expand Up @@ -170,7 +170,7 @@ describe('modules/platform/bitbucket/pr-cache', () => {
{ number: 1, title: 'title' },
]);
expect(cache).toEqual({
httpCache: {},
httpCache: expect.toBeNonEmptyObject(),
platform: {
bitbucket: {
pullRequestsCache: {
Expand Down
14 changes: 8 additions & 6 deletions lib/util/http/cache/abstract-http-cache-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,17 @@ export abstract class AbstractHttpCacheProvider implements HttpCacheProvider {
httpResponse,
timestamp,
});
if (newHttpCache) {
logger.debug(
`http cache: saving ${url} (etag=${etag}, lastModified=${lastModified})`,
);
await this.persist(url, newHttpCache as HttpCache);
} else {

// istanbul ignore if: should never happen
if (!newHttpCache) {
logger.debug(`http cache: failed to persist cache for ${url}`);
return resp;
}

logger.debug(
`http cache: saving ${url} (etag=${etag}, lastModified=${lastModified})`,
);
await this.persist(url, newHttpCache as HttpCache);
return resp;
}

Expand Down
14 changes: 0 additions & 14 deletions lib/util/http/cache/repository-http-cache-provider.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Http } from '..';
import * as httpMock from '../../../../test/http-mock';
import { logger } from '../../../../test/util';
import { resetCache } from '../../cache/repository';
import { repoCacheProvider } from './repository-http-cache-provider';

Expand Down Expand Up @@ -59,19 +58,6 @@ describe('util/http/cache/repository-http-cache-provider', () => {
});
});

it('reports if cache could not be persisted', async () => {
httpMock
.scope('https://example.com')
.get('/foo/bar')
.reply(200, { msg: 'Hello, world!' });

await http.getJsonUnchecked('https://example.com/foo/bar');

expect(logger.logger.debug).toHaveBeenCalledWith(
'http cache: failed to persist cache for https://example.com/foo/bar',
);
});

it('handles abrupt cache reset', async () => {
const scope = httpMock.scope('https://example.com');

Expand Down
4 changes: 0 additions & 4 deletions lib/util/http/cache/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ export const HttpCacheSchema = z
httpResponse: z.unknown(),
timestamp: z.string(),
})
.refine(
({ etag, lastModified }) => etag ?? lastModified,
'Cache object should have `etag` or `lastModified` fields',
)
.nullable()
.catch(null);
export type HttpCache = z.infer<typeof HttpCacheSchema>;

0 comments on commit b5ae2f5

Please sign in to comment.