«

What is Chrome(Electron) default cache size limit?

时间:2023-2-23     作者:new     分类: 其他


According to Chromium source, it uses kDefaultCacheSize = 80 * 1024 * 1024 Bytes --> 80MiB and applies the first matching rule of the following to determine the actual (disk, HTTP) cache size

默认缓存空间大小KD=80MB,匹配下列第一条符合的规则

So that should be 1% of the available disk space at startup in the common case, with a moderately filled HDD.


Chromium使用LRU(Least RecentUsed)最近最少使用算法来回收表项。因为磁盘存储的空间是优先的,不能无限的增长下去,所以对于很少使用到的表项,回收这一部分磁盘空间。

const MAX_CACHE_SIZE = 31457280 * 8

app.commandLine.appendSwitch('disk-cache-size', MAX_CACHE_SIZE)

    mainWindow.webContents.session.clearCache()

    console.log('size------')
    mainWindow.webContents.session.getCacheSize().then(res => {
        console.log(res)
        console.log(res / 1024 + ' K')
        if (res > MAX_CACHE_SIZE * 0.8) {
            console.log('---------clearCache-------')
            mainWindow.webContents.session.clearCache()
            mainWindow.webContents.session.clearStorageData()
        }

    })
    console.log('-----storagePath:' + mainWindow.webContents.session.storagePath)


标签: electron