MCPcopy
hub / github.com/prisma/prisma / cleanupCache

Function cleanupCache

packages/fetch-engine/src/cleanupCache.ts:11–38  ·  view source on GitHub ↗
(n = 5)

Source from the content-addressed store, hash-verified

9const debug = Debug('cleanupCache')
10
11export async function cleanupCache(n = 5): Promise<void> {
12 try {
13 const rootCacheDir = await getRootCacheDir()
14 if (!rootCacheDir) {
15 debug('no rootCacheDir found')
16 return
17 }
18 const channel = 'master'
19 const cacheDir = path.join(rootCacheDir, channel)
20 const dirs = await fs.promises.readdir(cacheDir)
21 const dirsWithMeta = await Promise.all(
22 dirs.map(async (dirName) => {
23 const dir = path.join(cacheDir, dirName)
24 const statResult = await fs.promises.stat(dir)
25
26 return {
27 dir,
28 created: statResult.birthtime,
29 }
30 }),
31 )
32 dirsWithMeta.sort((a, b) => (a.created < b.created ? 1 : -1))
33 const dirsToRemove = dirsWithMeta.slice(n)
34 await pMap(dirsToRemove, (dir) => fs.promises.rm(dir.dir, { force: true, recursive: true }), { concurrency: 20 })
35 } catch (e) {
36 // fail silently
37 }
38}

Callers 2

downloadFunction · 0.90
download.test.tsFile · 0.90

Calls 3

getRootCacheDirFunction · 0.90
debugFunction · 0.85
sliceMethod · 0.45

Tested by

no test coverage detected