mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-13 07:26:26 +00:00
fix(cache): improve repository cache robustness (#6689)
This commit is contained in:
parent
e015875ac5
commit
4459b11261
2 changed files with 7 additions and 3 deletions
2
lib/util/cache/repository/index.spec.ts
vendored
2
lib/util/cache/repository/index.spec.ts
vendored
|
@ -45,6 +45,6 @@ describe('lib/util/cache/repository', () => {
|
||||||
expect(fs.outputFile.mock.calls).toHaveLength(1);
|
expect(fs.outputFile.mock.calls).toHaveLength(1);
|
||||||
});
|
});
|
||||||
it('gets', () => {
|
it('gets', () => {
|
||||||
expect(repositoryCache.getCache()).toEqual({ repository: 'abc/def' });
|
expect(repositoryCache.getCache()).toEqual({});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
8
lib/util/cache/repository/index.ts
vendored
8
lib/util/cache/repository/index.ts
vendored
|
@ -56,15 +56,19 @@ export async function initialize(config: RenovateConfig): Promise<void> {
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.debug({ cacheFileName }, 'Repository cache not found');
|
logger.debug({ cacheFileName }, 'Repository cache not found');
|
||||||
}
|
}
|
||||||
cache = cache || { repository: config.repository };
|
cache = cache || Object.create({});
|
||||||
|
cache.repository = config.repository;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getCache(): Cache {
|
export function getCache(): Cache {
|
||||||
|
cache = cache || Object.create({});
|
||||||
return cache;
|
return cache;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function finalize(): Promise<void> {
|
export async function finalize(): Promise<void> {
|
||||||
if (repositoryCache !== 'disabled') {
|
if (cacheFileName && cache && repositoryCache !== 'disabled') {
|
||||||
await fs.outputFile(cacheFileName, JSON.stringify(cache));
|
await fs.outputFile(cacheFileName, JSON.stringify(cache));
|
||||||
}
|
}
|
||||||
|
cacheFileName = null;
|
||||||
|
cache = Object.create({});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue