更新说明:

1、规范化代码

Signed-off-by: 明月清风 <qiufeihu1@h-partners.com>
This commit is contained in:
明月清风 2024-04-30 10:06:48 +08:00
parent e65ee6bb81
commit 34cb7e64ea
7 changed files with 17 additions and 17 deletions

View File

@ -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<string,string> = new util.LRUCache(1024)
// 生成内存缓存

View File

@ -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'

View File

@ -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);
}

View File

@ -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<string, List<ImageKnifeRequestWithSource>> = 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;
}
}

View File

@ -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<string,string> = new util.LRUCache(1024)

View File

@ -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
}

View File

@ -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)
}
}