forked from floraachy/ImageKnife
更新说明:
1、规范化代码 Signed-off-by: 明月清风 <qiufeihu1@h-partners.com>
This commit is contained in:
parent
e65ee6bb81
commit
34cb7e64ea
|
@ -12,12 +12,12 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
import { EngineKeyInterface, ObjectKey } from '@ohos/imageknife';
|
|
||||||
import util from '@ohos.util';
|
import util from '@ohos.util';
|
||||||
|
import { IEngineKey, ObjectKey } from '@ohos/imageknife';
|
||||||
import { SparkMD5 } from '@ohos/imageknife/src/main/ets/3rd_party/sparkmd5/spark-md5';
|
import { SparkMD5 } from '@ohos/imageknife/src/main/ets/3rd_party/sparkmd5/spark-md5';
|
||||||
|
|
||||||
//全局自定义key demo
|
//全局自定义key demo
|
||||||
export class CustomEngineKeyImpl implements EngineKeyInterface {
|
export class CustomEngineKeyImpl implements IEngineKey {
|
||||||
private keyCache: util.LRUCache<string,string> = new util.LRUCache(1024)
|
private keyCache: util.LRUCache<string,string> = new util.LRUCache(1024)
|
||||||
|
|
||||||
// 生成内存缓存
|
// 生成内存缓存
|
||||||
|
|
|
@ -10,7 +10,10 @@ export { FileUtils } from './src/main/ets/utils/FileUtils'
|
||||||
|
|
||||||
export { LogUtil } from './src/main/ets/utils/LogUtil'
|
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'
|
export { ObjectKey } from './src/main/ets/model/ObjectKey'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ import { MemoryLruCache } from './utils/MemoryLruCache';
|
||||||
import { IMemoryCache } from './utils/IMemoryCache'
|
import { IMemoryCache } from './utils/IMemoryCache'
|
||||||
import { FileCache } from './utils/FileCache';
|
import { FileCache } from './utils/FileCache';
|
||||||
import { ImageKnifeDispatcher } from './ImageKnifeDispatcher';
|
import { ImageKnifeDispatcher } from './ImageKnifeDispatcher';
|
||||||
import { EngineKeyInterface } from './key/EngineKeyInterface';
|
import { IEngineKey } from './key/IEngineKey';
|
||||||
|
|
||||||
|
|
||||||
export class ImageKnife {
|
export class ImageKnife {
|
||||||
|
@ -122,7 +122,7 @@ export class ImageKnife {
|
||||||
this.dispatcher.setMaxRequests(concurrency)
|
this.dispatcher.setMaxRequests(concurrency)
|
||||||
}
|
}
|
||||||
|
|
||||||
setEngineKeyImpl(impl: EngineKeyInterface): void {
|
setEngineKeyImpl(impl: IEngineKey): void {
|
||||||
this.dispatcher.setEngineKeyImpl(impl);
|
this.dispatcher.setEngineKeyImpl(impl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,9 +31,8 @@ import { Constants } from './utils/Constants';
|
||||||
import taskpool from '@ohos.taskpool';
|
import taskpool from '@ohos.taskpool';
|
||||||
import { FileTypeUtil } from './utils/FileTypeUtil';
|
import { FileTypeUtil } from './utils/FileTypeUtil';
|
||||||
import util from '@ohos.util';
|
import util from '@ohos.util';
|
||||||
import { SparkMD5 } from './3rd_party/sparkmd5/spark-md5';
|
import { IEngineKey } from './key/IEngineKey';
|
||||||
import { EngineKeyInterface } from './key/EngineKeyInterface';
|
import { DefaultEngineKey } from './key/DefaultEngineKey';
|
||||||
import { EngineKeyFactories } from './key/EngineKeyFactories';
|
|
||||||
|
|
||||||
export class ImageKnifeDispatcher {
|
export class ImageKnifeDispatcher {
|
||||||
// 最大并发
|
// 最大并发
|
||||||
|
@ -43,7 +42,7 @@ export class ImageKnifeDispatcher {
|
||||||
// 执行中的请求
|
// 执行中的请求
|
||||||
executingJobMap: LightWeightMap<string, List<ImageKnifeRequestWithSource>> = new LightWeightMap();
|
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 {
|
showFromMemomry(request: ImageKnifeRequest, imageSrc: string | PixelMap | Resource, requestSource: ImageKnifeRequestSource): boolean {
|
||||||
let memoryCache: ImageKnifeData | undefined = ImageKnife.getInstance()
|
let memoryCache: ImageKnifeData | undefined = ImageKnife.getInstance()
|
||||||
|
@ -204,7 +203,7 @@ export class ImageKnifeDispatcher {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setEngineKeyImpl(impl: EngineKeyInterface): void {
|
setEngineKeyImpl(impl: IEngineKey): void {
|
||||||
this.engineKeyImpl = impl;
|
this.engineKeyImpl = impl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,9 +15,9 @@
|
||||||
import util from '@ohos.util';
|
import util from '@ohos.util';
|
||||||
import { SparkMD5 } from '../3rd_party/sparkmd5/spark-md5';
|
import { SparkMD5 } from '../3rd_party/sparkmd5/spark-md5';
|
||||||
import { ObjectKey } from '../model/ObjectKey';
|
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)
|
private keyCache: util.LRUCache<string,string> = new util.LRUCache(1024)
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
*/
|
*/
|
||||||
import { ObjectKey } from '../model/ObjectKey'
|
import { ObjectKey } from '../model/ObjectKey'
|
||||||
|
|
||||||
export interface EngineKeyInterface {
|
export interface IEngineKey {
|
||||||
// 生成缓存key
|
// 生成缓存key
|
||||||
generateCacheKey(loadSrc: string | PixelMap | Resource, signature?: ObjectKey | undefined): string
|
generateCacheKey(loadSrc: string | PixelMap | Resource, signature?: ObjectKey | undefined): string
|
||||||
}
|
}
|
|
@ -243,9 +243,8 @@ export class FileCache {
|
||||||
*/
|
*/
|
||||||
static saveFileCacheOnlyFile(context: Context, key: string, value: ArrayBuffer): boolean {
|
static saveFileCacheOnlyFile(context: Context, key: string, value: ArrayBuffer): boolean {
|
||||||
// 写文件
|
// 写文件
|
||||||
let md5Key = SparkMD5.hashBinary(key)
|
|
||||||
FileUtils.getInstance()
|
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
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -257,8 +256,7 @@ export class FileCache {
|
||||||
*/
|
*/
|
||||||
static getFileCacheByFile(context: Context, key: string): ArrayBuffer | undefined {
|
static getFileCacheByFile(context: Context, key: string): ArrayBuffer | undefined {
|
||||||
// 从文件获取查看是否有缓存
|
// 从文件获取查看是否有缓存
|
||||||
let md5Key = SparkMD5.hashBinary(key)
|
|
||||||
return FileUtils.getInstance()
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue