feat(图片缓存管理文件): 最大限制更改为200MB和200张
This commit is contained in:
parent
c7c987cc1a
commit
d4b80f0ea5
@ -11,8 +11,8 @@ class ImageCacheManager {
|
|||||||
this.imageCacheName = `likei-images-v${this.currentImageVersion}` // OSS图片
|
this.imageCacheName = `likei-images-v${this.currentImageVersion}` // OSS图片
|
||||||
this.assetCacheName = `likei-assets-v${this.currentImageVersion}` // 本地assets
|
this.assetCacheName = `likei-assets-v${this.currentImageVersion}` // 本地assets
|
||||||
|
|
||||||
this.maxCacheItems = 100 // 最大缓存数量(100张)
|
this.maxCacheItems = 200 // 最大缓存数量(100张)
|
||||||
this.maxCacheSize = 100 * 1024 * 1024 // 最大缓存大小(100MB)
|
this.maxCacheSize = 200 * 1024 * 1024 // 最大缓存大小(100MB)
|
||||||
|
|
||||||
this.pendingRequests = new Map() // 请求去重的关键
|
this.pendingRequests = new Map() // 请求去重的关键
|
||||||
|
|
||||||
@ -80,7 +80,7 @@ class ImageCacheManager {
|
|||||||
case 'all':
|
case 'all':
|
||||||
// 清除所有相关缓存(除了动态内容)
|
// 清除所有相关缓存(除了动态内容)
|
||||||
cachesToClear = cacheNames.filter(
|
cachesToClear = cacheNames.filter(
|
||||||
(name) => name.startsWith('likei-images-v') || name.startsWith('likei-assets-v')
|
(name) => name.startsWith('likei-images-v') || name.startsWith('likei-assets-v'),
|
||||||
)
|
)
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
@ -124,7 +124,7 @@ class ImageCacheManager {
|
|||||||
else {
|
else {
|
||||||
const isImageVersionChanged = this.isVersionChanged(
|
const isImageVersionChanged = this.isVersionChanged(
|
||||||
cachedImageVersion || '1.0.0',
|
cachedImageVersion || '1.0.0',
|
||||||
IMAGE_CACHE_VERSION.version
|
IMAGE_CACHE_VERSION.version,
|
||||||
)
|
)
|
||||||
|
|
||||||
// 图片版本变化:根据配置清除指定类型的缓存
|
// 图片版本变化:根据配置清除指定类型的缓存
|
||||||
@ -255,7 +255,7 @@ class ImageCacheManager {
|
|||||||
const cacheNames = await caches.keys()
|
const cacheNames = await caches.keys()
|
||||||
const oldImageCaches = cacheNames.filter(
|
const oldImageCaches = cacheNames.filter(
|
||||||
(name) =>
|
(name) =>
|
||||||
name.startsWith('likei-images-v') && !name.includes(`v${this.currentImageVersion}`) // 排除当前版本的缓存
|
name.startsWith('likei-images-v') && !name.includes(`v${this.currentImageVersion}`), // 排除当前版本的缓存
|
||||||
)
|
)
|
||||||
|
|
||||||
console.log('正在清除旧的OSS图片缓存:', oldImageCaches)
|
console.log('正在清除旧的OSS图片缓存:', oldImageCaches)
|
||||||
@ -273,7 +273,7 @@ class ImageCacheManager {
|
|||||||
const cacheNames = await caches.keys()
|
const cacheNames = await caches.keys()
|
||||||
const oldAssetCaches = cacheNames.filter(
|
const oldAssetCaches = cacheNames.filter(
|
||||||
(name) =>
|
(name) =>
|
||||||
name.startsWith('likei-assets-v') && !name.includes(`v${this.currentImageVersion}`) // 排除当前版本的缓存
|
name.startsWith('likei-assets-v') && !name.includes(`v${this.currentImageVersion}`), // 排除当前版本的缓存
|
||||||
)
|
)
|
||||||
|
|
||||||
console.log('正在清除旧的本地assets缓存:', oldAssetCaches)
|
console.log('正在清除旧的本地assets缓存:', oldAssetCaches)
|
||||||
@ -290,7 +290,7 @@ class ImageCacheManager {
|
|||||||
try {
|
try {
|
||||||
const cacheNames = await caches.keys()
|
const cacheNames = await caches.keys()
|
||||||
const allCaches = cacheNames.filter(
|
const allCaches = cacheNames.filter(
|
||||||
(name) => name.startsWith('likei-images-v') || name.startsWith('likei-assets-v')
|
(name) => name.startsWith('likei-images-v') || name.startsWith('likei-assets-v'),
|
||||||
)
|
)
|
||||||
|
|
||||||
console.log('正在清除所有图片缓存:', allCaches)
|
console.log('正在清除所有图片缓存:', allCaches)
|
||||||
@ -309,7 +309,7 @@ class ImageCacheManager {
|
|||||||
const containsAssets = normalizedUrl.includes('/assets/')
|
const containsAssets = normalizedUrl.includes('/assets/')
|
||||||
const containsOssH5 = normalizedUrl.includes('/oss/h5/')
|
const containsOssH5 = normalizedUrl.includes('/oss/h5/')
|
||||||
const startsWithOss = normalizedUrl.startsWith(
|
const startsWithOss = normalizedUrl.startsWith(
|
||||||
'https://tkm-likei.oss-ap-southeast-1.aliyuncs.com/h5/'
|
'https://tkm-likei.oss-ap-southeast-1.aliyuncs.com/h5/',
|
||||||
)
|
)
|
||||||
|
|
||||||
// 只缓存三种类型的资源
|
// 只缓存三种类型的资源
|
||||||
@ -444,7 +444,7 @@ class ImageCacheManager {
|
|||||||
new Request(normalizedUrl, {
|
new Request(normalizedUrl, {
|
||||||
mode: 'cors',
|
mode: 'cors',
|
||||||
credentials: 'omit',
|
credentials: 'omit',
|
||||||
})
|
}),
|
||||||
)
|
)
|
||||||
|
|
||||||
if (!cachedResponse) {
|
if (!cachedResponse) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user