What is Chrome(Electron) default cache size limit?
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,匹配下列第一条符合的规则
- 80% of the available space if there is not enough space to use kDefaultCacheSize
- 如果可用磁盘空间(A) < KD 则缓存空间为A*80%
- kDefaultCacheSize if it uses 10% to 80% of the available space
- 如果使用了可用空间的10%到80%,则缓存空间大小为KD
- 10% of the available space if the target size (2.5 * kDefaultCacheSize) is more than 10%
- 如果KD*2.5 > A*10%,则缓存空间大小为A*10%
- the target size (2.5 * kDefaultCacheSize) if it uses 10% to 1% of the available space
-
如果使用了可用空间的10%到1%,则缓存空间大小为2.5*KD
- 1% of the available space
- 可用空间的1%
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)
本文出自 码农,转载时请注明出处及相应链接。
发表评论