Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: global cache return undefined instead of null #6530

Merged
merged 2 commits into from Jun 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/util/cache/global/file.spec.ts
Expand Up @@ -7,7 +7,9 @@ describe('lib/util/cache/global/file', () => {
});

it('gets null', async () => {
expect(await global.renovateCache.get('test', 'missing-key')).toBeNull();
expect(
await global.renovateCache.get('test', 'missing-key')
).toBeUndefined();
});

it('sets and gets', async () => {
Expand All @@ -17,6 +19,6 @@ describe('lib/util/cache/global/file', () => {

it('expires', async () => {
await global.renovateCache.set('test', 'key', 1234, -5);
expect(await global.renovateCache.get('test', 'key')).toBeNull();
expect(await global.renovateCache.get('test', 'key')).toBeUndefined();
});
});
3 changes: 1 addition & 2 deletions lib/util/cache/global/file.ts
Expand Up @@ -18,7 +18,6 @@ async function get<T = never>(namespace: string, key: string): Promise<T> {
try {
const res = await cacache.get(renovateCache, getKey(namespace, key));
const cachedValue = JSON.parse(res.data.toString());
// istanbul ignore else: only happens when cache is corrupted
if (cachedValue) {
if (DateTime.local() < DateTime.fromISO(cachedValue.expiry)) {
logger.trace({ namespace, key }, 'Returning cached value');
Expand All @@ -29,7 +28,7 @@ async function get<T = never>(namespace: string, key: string): Promise<T> {
} catch (err) {
logger.trace({ namespace, key }, 'Cache miss');
}
return null;
return undefined;
}

async function set(
Expand Down
2 changes: 1 addition & 1 deletion lib/util/cache/global/redis.ts
Expand Up @@ -38,7 +38,7 @@ async function get<T = never>(namespace: string, key: string): Promise<T> {
} catch (err) {
logger.trace({ namespace, key }, 'Cache miss');
}
return null;
return undefined;
}

async function set(
Expand Down