diff --git a/README.md b/README.md index c329bfe..66817d8 100644 --- a/README.md +++ b/README.md @@ -138,22 +138,22 @@ ImageKnifeComponent({ ImageKnifeOption: ## 接口说明 ### ImageKnifeOption参数列表 -| 参数名称 | 入参内容 | 功能简介 | -|-----------------------|-------------------------------|-----------------| -| loadSrc | string、PixelMap、Resource | 主图展示 | -| placeholderSrc | PixelMap、Resource | 占位图图展示(可选) | -| errorholderSrc | PixelMap、Resource | 错误图展示(可选) | -| objectFit | ImageFit | 图片展示样式(可选) | -| writeCacheStrategy | WriteCacheStrategyType | 写入缓存策略(可选) | -| onlyRetrieveFromCache | boolean | 是否跳过网络和本地请求(可选) | +| 参数名称 | 入参内容 | 功能简介 | +|-----------------------|--------------------------------|-----------------| +| loadSrc | string、PixelMap、Resource | 主图展示 | +| placeholderSrc | PixelMap、Resource | 占位图图展示(可选) | +| errorholderSrc | PixelMap、Resource | 错误图展示(可选) | +| objectFit | ImageFit | 图片展示样式(可选) | +| writeCacheStrategy | WriteCacheStrategyType | 写入缓存策略(可选) | +| onlyRetrieveFromCache | boolean | 是否跳过网络和本地请求(可选) | | customGetImage | (context: Context, src: string | 自定义下载图片(可选) | | Resource | 错误占位图数据源 | -| border | BorderOptions | 边框圆角(可选) | -| priority | taskpool.Priority | 加载优先级(可选) | -| context | common.UIAbilityContext | 上下文(可选) | -| progressListener | (progress: number)=>void | 进度(可选) | -| signature | ObjectKey | 自定义缓存关键字(可选) | -| headerOption | Array | 设置请求头(可选) | -| transformation | PixelMapTransformation | 图片变换(可选) | +| border | BorderOptions | 边框圆角(可选) | +| priority | taskpool.Priority | 加载优先级(可选) | +| context | common.UIAbilityContext | 上下文(可选) | +| progressListener | (progress: number)=>void | 进度(可选) | +| signature | String | 自定义缓存关键字(可选) | +| headerOption | Array | 设置请求头(可选) | +| transformation | PixelMapTransformation | 图片变换(可选) | ### ImageKnife接口 | 参数名称 | 入参内容 | 功能简介 | diff --git a/entry/src/main/ets/common/CustomEngineKeyImpl.ets b/entry/src/main/ets/common/CustomEngineKeyImpl.ets index 5af4cba..60af07a 100644 --- a/entry/src/main/ets/common/CustomEngineKeyImpl.ets +++ b/entry/src/main/ets/common/CustomEngineKeyImpl.ets @@ -12,46 +12,35 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import util from '@ohos.util'; -import { IEngineKey, ImageKnifeOption, ObjectKey , PixelMapTransformation } from '@ohos/imageknife'; +import { IEngineKey, ImageKnifeOption, PixelMapTransformation } from '@ohos/imageknife'; import { SparkMD5 } from '@ohos/imageknife/src/main/ets/3rd_party/sparkmd5/spark-md5'; +import { ImageKnifeRequestSource } from '@ohos/imageknife/src/main/ets/ImageKnifeDispatcher'; //全局自定义key demo +@Sendable export class CustomEngineKeyImpl implements IEngineKey { - private memoryKeyCache: util.LRUCache = new util.LRUCache(1024) - private fileKeyCache: util.LRUCache = new util.LRUCache(1024) - // 生成内存缓存key - generateMemoryKey(loadSrc: string | PixelMap | Resource, imageKnifeOption: ImageKnifeOption): string { - let src = "loadSrc=" + (typeof loadSrc == "string" ? loadSrc : JSON.stringify(loadSrc)) + ";" - if (imageKnifeOption.signature) { - src += "signature=" + imageKnifeOption.signature.getKey() + ";" + generateMemoryKey(loadSrc: string | PixelMap | Resource, requestSource: ImageKnifeRequestSource, + imageKnifeOption: ImageKnifeOption, width?: number, height?: number): string { + let key = "loadSrc=" + (typeof loadSrc == "string" ? loadSrc : JSON.stringify(loadSrc)) + ";" + if (requestSource === ImageKnifeRequestSource.SRC) { + if (imageKnifeOption.signature !== undefined && imageKnifeOption.signature !== "") { + key += "signature=" + imageKnifeOption.signature + ";" + } + if (imageKnifeOption.transformation) { + key += "transformation=" + this.getTransformation(imageKnifeOption.transformation) + ";" + } } - if (imageKnifeOption.transformation) { - src += "transformation=" + this.getTransformation(imageKnifeOption.transformation) + ";" - } - return this.generateKey(src, this.memoryKeyCache) + return key } // 生成文件缓存key - generateFileKey(loadSrc: string | PixelMap | Resource, signature?: ObjectKey | undefined): string { - let src = "loadSrc=" + (typeof loadSrc == "string" ? loadSrc : JSON.stringify(loadSrc)) + ";" - if (signature) { - src += "signature=" + signature.getKey() + ";" - } - return this.generateKey(src, this.fileKeyCache) - } - - // key缓存策略,避免无意义的 JSON.stringify - private generateKey(keyCache: string, cache: util.LRUCache): string { - let result = cache.get(keyCache) - if (result != undefined) { - return result - } else { - result = SparkMD5.hashBinary(keyCache) - cache.put(keyCache, result) - return result + generateFileKey(loadSrc: string | PixelMap | Resource, signature?: string): string { + let src = "loadSrc=" + (typeof loadSrc == "string" ? loadSrc : JSON.stringify(loadSrc)) + ";" + if (signature !== undefined && signature !== "") { + src += "signature=" + signature + ";" } + return SparkMD5.hashBinary(src) } private getTransformation(transformation: PixelMapTransformation): string { diff --git a/entry/src/main/ets/pages/SignatureTestPage.ets b/entry/src/main/ets/pages/SignatureTestPage.ets index 4ada805..445dc26 100644 --- a/entry/src/main/ets/pages/SignatureTestPage.ets +++ b/entry/src/main/ets/pages/SignatureTestPage.ets @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 Huawei Device Co., Ltd. + * Copyright (C) 2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { ImageKnifeComponent, ImageKnifeOption, ObjectKey } from '@ohos/imageknife'; +import { ImageKnifeComponent, ImageKnifeOption } from '@ohos/imageknife'; @Entry @@ -40,7 +40,7 @@ struct SignatureTestPage { this.imageKnifeOption1 = { loadSrc: 'https://img-blog.csdn.net/20140514114029140', placeholderSrc:$r("app.media.loading"), - signature: new ObjectKey("1") + signature: "1" } }).margin({ top: 5, left: 3 }) ImageKnifeComponent({ imageKnifeOption: this.imageKnifeOption1 }).width(300).height(300) @@ -53,7 +53,7 @@ struct SignatureTestPage { this.imageKnifeOption2 = { loadSrc: 'https://img-blog.csdn.net/20140514114029140', placeholderSrc:$r("app.media.loading"), - signature: new ObjectKey(new Date().getTime().toString()) + signature: new Date().getTime().toString() } }).margin({ top: 5, left: 3 }) ImageKnifeComponent({ imageKnifeOption: this.imageKnifeOption2 }).width(300).height(300) @@ -66,7 +66,7 @@ struct SignatureTestPage { } aboutToAppear() { - console.log("唯一标识页面:" + new ObjectKey(new Date().getTime().toString()).getKey()) + console.log("唯一标识页面:" + new Date().getTime().toString()) } } \ No newline at end of file diff --git a/library/index.ets b/library/index.ets index eb1a473..7b2a45d 100644 --- a/library/index.ets +++ b/library/index.ets @@ -12,8 +12,6 @@ export { LogUtil } from './src/main/ets/utils/LogUtil' export { IEngineKey } from './src/main/ets/key/IEngineKey' -export { ObjectKey } from './src/main/ets/model/ObjectKey' - export { ImageKnifeData , ReadCacheStrategyType} from "./src/main/ets/model/ImageKnifeData" export { PixelMapTransformation } from './src/main/ets/transform/PixelMapTransformation' diff --git a/library/src/main/ets/ImageKnife.ets b/library/src/main/ets/ImageKnife.ets index 0a2cc5e..94202f2 100644 --- a/library/src/main/ets/ImageKnife.ets +++ b/library/src/main/ets/ImageKnife.ets @@ -17,7 +17,7 @@ import { ReadCacheStrategyType, ImageKnifeData } from './model/ImageKnifeData'; import { MemoryLruCache } from './utils/MemoryLruCache'; import { IMemoryCache } from './utils/IMemoryCache' import { FileCache } from './utils/FileCache'; -import { ImageKnifeDispatcher } from './ImageKnifeDispatcher'; +import { ImageKnifeDispatcher, ImageKnifeRequestSource } from './ImageKnifeDispatcher'; import { IEngineKey } from './key/IEngineKey'; import { HeaderOptions, ImageKnifeOption } from './ImageKnifeOption'; import { DefaultEngineKey } from './key/DefaultEngineKey'; @@ -120,17 +120,17 @@ export class ImageKnife { return this.fileCache as FileCache } /** - * 预加载到缓存 + * 预加载到文件缓存 * @param loadSrc 图片地址url * @returns 返回文件缓存路径 */ - preLoadCache(loadSrc:string): Promise { + preLoadCache(loadSrc: string): Promise { return new Promise((resolve,reject)=>{ let imageKnifeOption = new ImageKnifeOption() imageKnifeOption.loadSrc = loadSrc let engineKeyImpl: IEngineKey = new DefaultEngineKey() - let keys = engineKeyImpl.generateMemoryKey(loadSrc, imageKnifeOption) - let cachePath = ImageKnife.getInstance().getFileCache().getFileToPath(keys) + let fileKey = engineKeyImpl.generateFileKey(loadSrc) + let cachePath = ImageKnife.getInstance().getFileCache().getFileToPath(fileKey) if(cachePath == null || cachePath == "" || cachePath == undefined) { let request = new ImageKnifeRequest( imageKnifeOption, @@ -140,7 +140,7 @@ export class ImageKnife { 0, { showPixelMap(version: number, pixelMap: PixelMap | string) { - resolve(ImageKnife.getInstance().getFileCache().getFileToPath(keys)) + resolve(ImageKnife.getInstance().getFileCache().getFileToPath(fileKey)) } } ) @@ -176,9 +176,9 @@ export class ImageKnife { } private readMemoryCache(loadSrc: string,option: ImageKnifeOption, engineKey: IEngineKey): ImageKnifeData | undefined { - let keys = engineKey.generateMemoryKey(loadSrc,option) + let memoryKey = engineKey.generateMemoryKey(loadSrc, ImageKnifeRequestSource.SRC, option) return ImageKnife.getInstance() - .loadFromMemoryCache(keys) + .loadFromMemoryCache(memoryKey) } private readFileCache(loadSrc:string,engineKey:IEngineKey,onComplete:(data:ImageKnifeData | undefined)=>void){ diff --git a/library/src/main/ets/ImageKnifeDispatcher.ets b/library/src/main/ets/ImageKnifeDispatcher.ets index 5e2a54f..26c9047 100644 --- a/library/src/main/ets/ImageKnifeDispatcher.ets +++ b/library/src/main/ets/ImageKnifeDispatcher.ets @@ -44,11 +44,11 @@ export class ImageKnifeDispatcher { // 执行中的请求 executingJobMap: LightWeightMap> = new LightWeightMap(); // 开发者可配置全局缓存 - private engineKeyImpl: IEngineKey = new DefaultEngineKey(); + private engineKey: IEngineKey = new DefaultEngineKey(); showFromMemomry(request: ImageKnifeRequest, imageSrc: string | PixelMap | Resource, requestSource: ImageKnifeRequestSource): boolean { let memoryCache: ImageKnifeData | undefined = ImageKnife.getInstance() - .loadFromMemoryCache(this.engineKeyImpl.generateMemoryKey(imageSrc, request.imageKnifeOption)) + .loadFromMemoryCache(this.engineKey.generateMemoryKey(imageSrc, requestSource, request.imageKnifeOption)) if (memoryCache !== undefined) { // 画主图 if (request.requestState === ImageKnifeRequestState.PROGRESS) { @@ -97,13 +97,12 @@ export class ImageKnifeDispatcher { * 获取和显示图片 */ getAndShowImage(currentRequest: ImageKnifeRequest, imageSrc: string | PixelMap | Resource, requestSource: ImageKnifeRequestSource): void { - let keyMemory: string = this.engineKeyImpl.generateMemoryKey(imageSrc, currentRequest.imageKnifeOption) - let keyFile: string = this.engineKeyImpl.generateFileKey(imageSrc, currentRequest.imageKnifeOption.signature) - let requestList: List | undefined = this.executingJobMap.get(keyMemory) + let memoryKey: string = this.engineKey.generateMemoryKey(imageSrc,requestSource, currentRequest.imageKnifeOption) + let requestList: List | undefined = this.executingJobMap.get(memoryKey) if (requestList == undefined) { requestList = new List() requestList.add({ request: currentRequest, source: requestSource }) - this.executingJobMap.set(keyMemory, requestList) + this.executingJobMap.set(memoryKey, requestList) } else { requestList.add({ request: currentRequest, source: requestSource }) return @@ -112,13 +111,14 @@ export class ImageKnifeDispatcher { let request: RequestJobRequest = { context: currentRequest.context, src: imageSrc, - key: keyFile, headers:currentRequest.imageKnifeOption.headerOption, allHeaders:currentRequest.headers, customGetImage: currentRequest.imageKnifeOption.customGetImage, onlyRetrieveFromCache: currentRequest.imageKnifeOption.onlyRetrieveFromCache, transformation:currentRequest.imageKnifeOption.transformation, writeCacheStrategy: currentRequest.imageKnifeOption.writeCacheStrategy, + engineKey: this.engineKey, + signature: currentRequest.imageKnifeOption.signature, requestSource } // 启动线程下载和解码主图 @@ -144,15 +144,15 @@ export class ImageKnifeDispatcher { } } }); - this.executingJobMap.remove(keyMemory) + this.executingJobMap.remove(memoryKey) } else { - LogUtil.log("error: no requestlist need to draw for key = " + keyMemory) + LogUtil.log("error: no requestlist need to draw for key = " + memoryKey) } } // 保存文件缓存 if (requestJobResult.bufferSize > 0 && currentRequest.imageKnifeOption.writeCacheStrategy !== WriteCacheStrategyType.Memory) { - ImageKnife.getInstance().saveWithoutWriteFile(keyFile, requestJobResult.bufferSize) + ImageKnife.getInstance().saveWithoutWriteFile(requestJobResult.fileKey, requestJobResult.bufferSize) } let ImageKnifeData: ImageKnifeData = { @@ -164,7 +164,7 @@ export class ImageKnifeDispatcher { // 保存内存缓存 if(currentRequest.imageKnifeOption.writeCacheStrategy !== WriteCacheStrategyType.File) { ImageKnife.getInstance() - .saveMemoryCache(this.engineKeyImpl.generateMemoryKey(imageSrc, currentRequest.imageKnifeOption), + .saveMemoryCache(this.engineKey.generateMemoryKey(imageSrc, requestSource, currentRequest.imageKnifeOption), ImageKnifeData) } if (requestList !== undefined) { @@ -190,11 +190,11 @@ export class ImageKnifeDispatcher { }); - this.executingJobMap.remove(keyMemory) + this.executingJobMap.remove(memoryKey) this.dispatchNextJob() } else { - LogUtil.log("error: no requestlist need to draw for key = " + keyMemory) + LogUtil.log("error: no requestlist need to draw for key = " + memoryKey) } // }) @@ -215,7 +215,7 @@ export class ImageKnifeDispatcher { } setEngineKeyImpl(impl: IEngineKey): void { - this.engineKeyImpl = impl; + this.engineKey = impl; } } @@ -235,10 +235,13 @@ async function requestJob(request: RequestJobRequest): Promise = {} @@ -309,11 +307,11 @@ async function requestJob(request: RequestJobRequest): Promise, allHeaders:Map, customGetImage?: (context: Context, src: string | PixelMap | Resource) => Promise, @@ -402,4 +402,6 @@ interface RequestJobRequest { requestSource:ImageKnifeRequestSource transformation?: PixelMapTransformation writeCacheStrategy?: WriteCacheStrategyType + signature?: string + engineKey:IEngineKey } diff --git a/library/src/main/ets/ImageKnifeOption.ets b/library/src/main/ets/ImageKnifeOption.ets index ac04132..db63dfe 100644 --- a/library/src/main/ets/ImageKnifeOption.ets +++ b/library/src/main/ets/ImageKnifeOption.ets @@ -14,7 +14,6 @@ */ import taskpool from '@ohos.taskpool'; import common from '@ohos.app.ability.common' -import { ObjectKey } from './model/ObjectKey'; import { WriteCacheStrategyType } from './model/ImageKnifeData'; import { PixelMapTransformation } from './transform/PixelMapTransformation'; @@ -34,7 +33,7 @@ export class ImageKnifeOption { headerOption?: Array; // 自定义缓存关键字 - signature?: ObjectKey; + signature?: string; objectFit?: ImageFit diff --git a/library/src/main/ets/key/DefaultEngineKey.ets b/library/src/main/ets/key/DefaultEngineKey.ets index 9ed379e..8520701 100644 --- a/library/src/main/ets/key/DefaultEngineKey.ets +++ b/library/src/main/ets/key/DefaultEngineKey.ets @@ -12,48 +12,36 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import util from '@ohos.util'; import { SparkMD5 } from '../3rd_party/sparkmd5/spark-md5'; import { ImageKnifeOption } from '../ImageKnifeOption'; import { IEngineKey } from './IEngineKey'; -import { ObjectKey } from '../model/ObjectKey'; import { PixelMapTransformation } from '../transform/PixelMapTransformation'; +import { ImageKnifeRequestSource } from '../ImageKnifeDispatcher'; +@Sendable export class DefaultEngineKey implements IEngineKey { - private memoryKeyCache: util.LRUCache = new util.LRUCache(1024) - private fileKeyCache: util.LRUCache = new util.LRUCache(1024) - // 生成内存缓存key - generateMemoryKey(loadSrc: string | PixelMap | Resource, imageKnifeOption: ImageKnifeOption): string { - let src = "loadSrc=" + (typeof loadSrc == "string" ? loadSrc : JSON.stringify(loadSrc)) + ";" - if (imageKnifeOption.signature) { - src += "signature=" + imageKnifeOption.signature.getKey() + ";" + generateMemoryKey(loadSrc: string | PixelMap | Resource, requestSource: ImageKnifeRequestSource, + imageKnifeOption: ImageKnifeOption, width?: number, height?: number): string { + let key = "loadSrc=" + (typeof loadSrc == "string" ? loadSrc : JSON.stringify(loadSrc)) + ";" + if (requestSource === ImageKnifeRequestSource.SRC) { + if (imageKnifeOption.signature !== undefined && imageKnifeOption.signature !== "") { + key += "signature=" + imageKnifeOption.signature + ";" + } + if (imageKnifeOption.transformation) { + key += "transformation=" + this.getTransformation(imageKnifeOption.transformation) + ";" + } } - if (imageKnifeOption.transformation) { - src += "transformation=" + this.getTransformation(imageKnifeOption.transformation) + ";" - } - return this.generateKey(src, this.memoryKeyCache) + return key } // 生成文件缓存key - generateFileKey(loadSrc: string | PixelMap | Resource, signature?: ObjectKey | undefined): string { - let src = "loadSrc=" + (typeof loadSrc == "string" ? loadSrc : JSON.stringify(loadSrc)) + ";" - if (signature) { - src += "signature=" + signature.getKey() + ";" - } - return this.generateKey(src, this.fileKeyCache) - } - - // key缓存策略,避免无意义的 JSON.stringify - private generateKey(keyCache: string, cache: util.LRUCache): string { - let result = cache.get(keyCache) - if (result != undefined) { - return result - } else { - result = SparkMD5.hashBinary(keyCache) - cache.put(keyCache, result) - return result + generateFileKey(loadSrc: string | PixelMap | Resource, signature?: string): string { + let src = "loadSrc=" + (typeof loadSrc == "string" ? loadSrc : JSON.stringify(loadSrc)) + ";" + if (signature !== undefined && signature !== "") { + src += "signature=" + signature + ";" } + return SparkMD5.hashBinary(src) } private getTransformation(transformation: PixelMapTransformation): string { diff --git a/library/src/main/ets/key/IEngineKey.ets b/library/src/main/ets/key/IEngineKey.ets index 71e30d9..d8e949a 100644 --- a/library/src/main/ets/key/IEngineKey.ets +++ b/library/src/main/ets/key/IEngineKey.ets @@ -12,15 +12,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +import { ImageKnifeRequestSource } from '../ImageKnifeDispatcher' import { ImageKnifeOption } from '../ImageKnifeOption' -import { ObjectKey } from '../model/ObjectKey' export interface IEngineKey { // 生成内存缓存key - generateMemoryKey(loadSrc: string | PixelMap | Resource, imageKnifeOption: ImageKnifeOption): string + generateMemoryKey(loadSrc: string | PixelMap | Resource, requestSource: ImageKnifeRequestSource, + imageKnifeOption: ImageKnifeOption, width?: number, height?: number): string // 生成文件缓存key - generateFileKey(loadSrc: string | PixelMap | Resource, signature?: ObjectKey | undefined): string + generateFileKey(loadSrc: string | PixelMap | Resource, signature?: string): string } diff --git a/library/src/main/ets/model/ObjectKey.ets b/library/src/main/ets/model/ObjectKey.ets deleted file mode 100644 index 9a121ae..0000000 --- a/library/src/main/ets/model/ObjectKey.ets +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -export class ObjectKey{ - - private objectKey: string; - - constructor(objectKey: string) { - this.objectKey = objectKey; - } - - getKey(): string{ - return this.objectKey; - } - - -} \ No newline at end of file diff --git a/library/src/main/ets/utils/FileCache.ets b/library/src/main/ets/utils/FileCache.ets index 82c889b..381096a 100644 --- a/library/src/main/ets/utils/FileCache.ets +++ b/library/src/main/ets/utils/FileCache.ets @@ -31,7 +31,7 @@ export class FileCache { maxSize: number = 0 path: string = "" private lruCache: util.LRUCache - static isInited: boolean = false + private isInited: boolean = false private context?: Context readonly defaultMaxSize: number = 512; readonly defaultSize: number = 128; @@ -57,7 +57,7 @@ export class FileCache { * 遍历缓存文件目录,初始化缓存 */ public async initFileCache() { - if (FileCache.isInited) { + if (this.isInited) { return } @@ -100,7 +100,7 @@ export class FileCache { } this.trimToSize(); - FileCache.isInited = true + this.isInited = true } // 添加缓存键值对,同时写文件 @@ -108,7 +108,7 @@ export class FileCache { if (key == null || value == null) { throw new Error('key or value is invalid '); } - if (!FileCache.isInited) { + if (!this.isInited) { return } @@ -132,7 +132,7 @@ export class FileCache { if (key == null || value == null) { throw new Error('key or value is invalid '); } - if (!FileCache.isInited) { + if (!this.isInited) { return } @@ -151,7 +151,7 @@ export class FileCache { } get(key: string): ArrayBuffer | undefined { - if (!FileCache.isInited) { + if (!this.isInited) { return } @@ -167,7 +167,7 @@ export class FileCache { if (key == null) { throw new Error('key is null,checking the parameter'); } - if (!FileCache.isInited) { + if (!this.isInited) { return } @@ -179,10 +179,10 @@ export class FileCache { } async removeAll(): Promise { - if (!FileCache.isInited) { + if (!this.isInited) { return } - FileCache.isInited = false + this.isInited = false this.lruCache.clear() this.currentMemory = 0; @@ -191,7 +191,7 @@ export class FileCache { await FileUtils.getInstance().deleteFile(this.path + filenames[i]) } - FileCache.isInited = true + this.isInited = true } size(): number { @@ -242,9 +242,6 @@ export class FileCache { * @param value */ static saveFileCacheOnlyFile(context: Context, key: string, value: ArrayBuffer): boolean { - if (!FileCache.isInited) { - return false - } // 写文件 FileUtils.getInstance() .writeFileSync(context.cacheDir + FileUtils.SEPARATOR + FileCache.CACHE_FOLDER + FileUtils.SEPARATOR + key, value)