mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-14 16:46:25 +00:00
fix: global cache return undefined instead of null (#6530)
This commit is contained in:
parent
f5a588eb5a
commit
a6843734ca
3 changed files with 6 additions and 5 deletions
6
lib/util/cache/global/file.spec.ts
vendored
6
lib/util/cache/global/file.spec.ts
vendored
|
@ -7,7 +7,9 @@ describe('lib/util/cache/global/file', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('gets null', async () => {
|
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 () => {
|
it('sets and gets', async () => {
|
||||||
|
@ -17,6 +19,6 @@ describe('lib/util/cache/global/file', () => {
|
||||||
|
|
||||||
it('expires', async () => {
|
it('expires', async () => {
|
||||||
await global.renovateCache.set('test', 'key', 1234, -5);
|
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
lib/util/cache/global/file.ts
vendored
3
lib/util/cache/global/file.ts
vendored
|
@ -18,7 +18,6 @@ async function get<T = never>(namespace: string, key: string): Promise<T> {
|
||||||
try {
|
try {
|
||||||
const res = await cacache.get(renovateCache, getKey(namespace, key));
|
const res = await cacache.get(renovateCache, getKey(namespace, key));
|
||||||
const cachedValue = JSON.parse(res.data.toString());
|
const cachedValue = JSON.parse(res.data.toString());
|
||||||
// istanbul ignore else: only happens when cache is corrupted
|
|
||||||
if (cachedValue) {
|
if (cachedValue) {
|
||||||
if (DateTime.local() < DateTime.fromISO(cachedValue.expiry)) {
|
if (DateTime.local() < DateTime.fromISO(cachedValue.expiry)) {
|
||||||
logger.trace({ namespace, key }, 'Returning cached value');
|
logger.trace({ namespace, key }, 'Returning cached value');
|
||||||
|
@ -29,7 +28,7 @@ async function get<T = never>(namespace: string, key: string): Promise<T> {
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.trace({ namespace, key }, 'Cache miss');
|
logger.trace({ namespace, key }, 'Cache miss');
|
||||||
}
|
}
|
||||||
return null;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function set(
|
async function set(
|
||||||
|
|
2
lib/util/cache/global/redis.ts
vendored
2
lib/util/cache/global/redis.ts
vendored
|
@ -38,7 +38,7 @@ async function get<T = never>(namespace: string, key: string): Promise<T> {
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.trace({ namespace, key }, 'Cache miss');
|
logger.trace({ namespace, key }, 'Cache miss');
|
||||||
}
|
}
|
||||||
return null;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function set(
|
async function set(
|
||||||
|
|
Loading…
Reference in a new issue