diff --git a/entry/src/main/ets/common/CustomEngineKeyImpl.ets b/entry/src/main/ets/common/CustomEngineKeyImpl.ets index 887e678..6bbb9a1 100644 --- a/entry/src/main/ets/common/CustomEngineKeyImpl.ets +++ b/entry/src/main/ets/common/CustomEngineKeyImpl.ets @@ -12,12 +12,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { EngineKeyInterface, ObjectKey } from '@ohos/imageknife'; import util from '@ohos.util'; +import { IEngineKey, ObjectKey } from '@ohos/imageknife'; import { SparkMD5 } from '@ohos/imageknife/src/main/ets/3rd_party/sparkmd5/spark-md5'; //全局自定义key demo -export class CustomEngineKeyImpl implements EngineKeyInterface { +export class CustomEngineKeyImpl implements IEngineKey { private keyCache: util.LRUCache = new util.LRUCache(1024) // 生成内存缓存 diff --git a/library/index.ets b/library/index.ets index afc1896..255f3d7 100644 --- a/library/index.ets +++ b/library/index.ets @@ -10,7 +10,10 @@ export { FileUtils } from './src/main/ets/utils/FileUtils' export { LogUtil } from './src/main/ets/utils/LogUtil' -export { EngineKeyInterface } from './src/main/ets/key/EngineKeyInterface' +export { IEngineKey } from './src/main/ets/key/IEngineKey' export { ObjectKey } from './src/main/ets/model/ObjectKey' + + + diff --git a/library/src/main/ets/ImageKnife.ets b/library/src/main/ets/ImageKnife.ets index 2c4498b..3d35f83 100644 --- a/library/src/main/ets/ImageKnife.ets +++ b/library/src/main/ets/ImageKnife.ets @@ -18,7 +18,7 @@ import { MemoryLruCache } from './utils/MemoryLruCache'; import { IMemoryCache } from './utils/IMemoryCache' import { FileCache } from './utils/FileCache'; import { ImageKnifeDispatcher } from './ImageKnifeDispatcher'; -import { EngineKeyInterface } from './key/EngineKeyInterface'; +import { IEngineKey } from './key/IEngineKey'; export class ImageKnife { @@ -122,7 +122,7 @@ export class ImageKnife { this.dispatcher.setMaxRequests(concurrency) } - setEngineKeyImpl(impl: EngineKeyInterface): void { + setEngineKeyImpl(impl: IEngineKey): void { this.dispatcher.setEngineKeyImpl(impl); } diff --git a/library/src/main/ets/ImageKnifeDispatcher.ets b/library/src/main/ets/ImageKnifeDispatcher.ets index 163c056..1287ad6 100644 --- a/library/src/main/ets/ImageKnifeDispatcher.ets +++ b/library/src/main/ets/ImageKnifeDispatcher.ets @@ -31,9 +31,8 @@ import { Constants } from './utils/Constants'; import taskpool from '@ohos.taskpool'; import { FileTypeUtil } from './utils/FileTypeUtil'; import util from '@ohos.util'; -import { SparkMD5 } from './3rd_party/sparkmd5/spark-md5'; -import { EngineKeyInterface } from './key/EngineKeyInterface'; -import { EngineKeyFactories } from './key/EngineKeyFactories'; +import { IEngineKey } from './key/IEngineKey'; +import { DefaultEngineKey } from './key/DefaultEngineKey'; export class ImageKnifeDispatcher { // 最大并发 @@ -43,7 +42,7 @@ export class ImageKnifeDispatcher { // 执行中的请求 executingJobMap: LightWeightMap> = new LightWeightMap(); // 开发者可配置全局缓存 - private engineKeyImpl: EngineKeyInterface = new EngineKeyFactories(); + private engineKeyImpl: IEngineKey = new DefaultEngineKey(); showFromMemomry(request: ImageKnifeRequest, imageSrc: string | PixelMap | Resource, requestSource: ImageKnifeRequestSource): boolean { let memoryCache: ImageKnifeData | undefined = ImageKnife.getInstance() @@ -204,7 +203,7 @@ export class ImageKnifeDispatcher { } } - setEngineKeyImpl(impl: EngineKeyInterface): void { + setEngineKeyImpl(impl: IEngineKey): void { this.engineKeyImpl = impl; } } diff --git a/library/src/main/ets/key/EngineKeyFactories.ets b/library/src/main/ets/key/DefaultEngineKey.ets similarity index 92% rename from library/src/main/ets/key/EngineKeyFactories.ets rename to library/src/main/ets/key/DefaultEngineKey.ets index 078f574..6c66985 100644 --- a/library/src/main/ets/key/EngineKeyFactories.ets +++ b/library/src/main/ets/key/DefaultEngineKey.ets @@ -15,9 +15,9 @@ import util from '@ohos.util'; import { SparkMD5 } from '../3rd_party/sparkmd5/spark-md5'; import { ObjectKey } from '../model/ObjectKey'; -import { EngineKeyInterface } from './EngineKeyInterface'; +import { IEngineKey } from './IEngineKey'; -export class EngineKeyFactories implements EngineKeyInterface { +export class DefaultEngineKey implements IEngineKey { private keyCache: util.LRUCache = new util.LRUCache(1024) diff --git a/library/src/main/ets/key/EngineKeyInterface.ets b/library/src/main/ets/key/IEngineKey.ets similarity index 95% rename from library/src/main/ets/key/EngineKeyInterface.ets rename to library/src/main/ets/key/IEngineKey.ets index 1e127ed..d832d79 100644 --- a/library/src/main/ets/key/EngineKeyInterface.ets +++ b/library/src/main/ets/key/IEngineKey.ets @@ -14,7 +14,7 @@ */ import { ObjectKey } from '../model/ObjectKey' -export interface EngineKeyInterface { +export interface IEngineKey { // 生成缓存key generateCacheKey(loadSrc: string | PixelMap | Resource, signature?: ObjectKey | undefined): string } diff --git a/library/src/main/ets/utils/FileCache.ets b/library/src/main/ets/utils/FileCache.ets index 4260966..eaf357e 100644 --- a/library/src/main/ets/utils/FileCache.ets +++ b/library/src/main/ets/utils/FileCache.ets @@ -243,9 +243,8 @@ export class FileCache { */ static saveFileCacheOnlyFile(context: Context, key: string, value: ArrayBuffer): boolean { // 写文件 - let md5Key = SparkMD5.hashBinary(key) FileUtils.getInstance() - .writeFileSync(context.cacheDir + FileUtils.SEPARATOR + FileCache.CACHE_FOLDER + FileUtils.SEPARATOR + md5Key, value) + .writeFileSync(context.cacheDir + FileUtils.SEPARATOR + FileCache.CACHE_FOLDER + FileUtils.SEPARATOR + key, value) return true } @@ -257,8 +256,7 @@ export class FileCache { */ static getFileCacheByFile(context: Context, key: string): ArrayBuffer | undefined { // 从文件获取查看是否有缓存 - let md5Key = SparkMD5.hashBinary(key) return FileUtils.getInstance() - .readFileSync(context.cacheDir + FileUtils.SEPARATOR + FileCache.CACHE_FOLDER + FileUtils.SEPARATOR + md5Key) + .readFileSync(context.cacheDir + FileUtils.SEPARATOR + FileCache.CACHE_FOLDER + FileUtils.SEPARATOR + key) } } \ No newline at end of file