扩大内存和文件缓存的限制和默认值

Signed-off-by: madixin <madixin@huawei.com>
This commit is contained in:
madixin 2024-12-21 18:25:32 +08:00
parent fc6668cb0d
commit 2f2e562aed
3 changed files with 17 additions and 23 deletions

View File

@ -2,6 +2,7 @@
- Successful callback returns httpCode - Successful callback returns httpCode
- Fix bug: Network error code httpCode returns no data - Fix bug: Network error code httpCode returns no data
- Fix bug: Height adaptation leads to fixed component height - Fix bug: Height adaptation leads to fixed component height
- modify memory cache limit and file cache limit
## 3.2.0-rc.6 ## 3.2.0-rc.6
- Support LogUtil to turn off log - Support LogUtil to turn off log

View File

@ -16,7 +16,6 @@ import util from '@ohos.util';
import { FileUtils } from '../utils/FileUtils'; import { FileUtils } from '../utils/FileUtils';
import fs from '@ohos.file.fs'; import fs from '@ohos.file.fs';
import { LogUtil } from '../utils/LogUtil'; import { LogUtil } from '../utils/LogUtil';
import { SparkMD5 } from '../3rd_party/sparkmd5/spark-md5';
const INT_MAX = 2147483647 const INT_MAX = 2147483647
/** /**
@ -33,24 +32,21 @@ export class FileCache {
private lruCache: util.LRUCache<string, number> private lruCache: util.LRUCache<string, number>
private isInited: boolean = false private isInited: boolean = false
private context?: Context private context?: Context
readonly defaultMaxSize: number = 512; readonly defaultMaxMemorySize: number = 10 * 1024 * 1024 * 1024;
readonly defaultSize: number = INT_MAX; readonly defaultMemorySize: number = 1024 * 1024 * 1024;
readonly defaultMaxMemorySize: number = 512 * 1024 * 1024;
readonly defaultMemorySize: number = 128 * 1024 * 1024;
constructor(context: Context, size: number, memory: number) { constructor(context: Context, size: number, memory: number) {
if (size <= 0 || size > INT_MAX) { if (size <= 0 || size > INT_MAX) {
size = this.defaultSize size = INT_MAX;
} }
if (memory <= 0 || memory > this.defaultMaxMemorySize) { if (memory <= 0 || memory > this.defaultMaxMemorySize) {
memory = this.defaultMemorySize memory = this.defaultMemorySize;
} }
this.lruCache = new util.LRUCache(size); this.lruCache = new util.LRUCache(size);
this.maxMemory = memory this.maxMemory = memory;
this.currentMemory = 0; this.currentMemory = 0;
this.maxSize = size this.maxSize = size;
this.context = context this.context = context;
} }
/** /**
@ -204,8 +200,6 @@ export class FileCache {
for (let i = 0; i < filenames.length; i++) { for (let i = 0; i < filenames.length; i++) {
await FileUtils.getInstance().deleteFile(this.path + filenames[i]) await FileUtils.getInstance().deleteFile(this.path + filenames[i])
} }
this.isInited = true
} }
size(): number { size(): number {

View File

@ -21,23 +21,23 @@ export class MemoryLruCache implements IMemoryCache {
currentMemory: number = 0 currentMemory: number = 0
maxSize: number = 0 maxSize: number = 0
private lruCache: util.LRUCache<string, ImageKnifeData> private lruCache: util.LRUCache<string, ImageKnifeData>
readonly defaultMaxSize: number = 4096 readonly defaultMaxSize: number = 65536;
readonly defaultSize: number = 512 readonly defaultSize: number = 512;
readonly defaultMaxMemorySize: number = 1024 * 1024 * 1024 readonly defaultMaxMemorySize: number = 10 * 1024 * 1024 * 1024;
readonly defaultMemorySize: number = 128 * 1024 * 1024 readonly defaultMemorySize: number = 1024 * 1024 * 1024;
constructor(size: number, memory: number) { constructor(size: number, memory: number) {
if (size <= 0 || size > this.defaultMaxSize) { if (size <= 0 || size > this.defaultMaxSize) {
size = this.defaultSize size = this.defaultSize;
} }
if (memory <= 0 || memory > this.defaultMaxMemorySize) { if (memory <= 0 || memory > this.defaultMaxMemorySize) {
memory = this.defaultMemorySize memory = this.defaultMemorySize;
} }
this.lruCache = new util.LRUCache(size); this.lruCache = new util.LRUCache(size);
this.maxMemory = memory this.maxMemory = memory;
this.maxSize = size this.maxSize = size;
this.currentMemory = 0 this.currentMemory = 0;
} }
// 添加缓存键值对 // 添加缓存键值对
@ -117,7 +117,6 @@ export class MemoryLruCache implements IMemoryCache {
this.currentMemory -= value.source.getPixelBytesNumber(); this.currentMemory -= value.source.getPixelBytesNumber();
// value.source.release() // value.source.release()
} }
// LogUtil.info('MemoryCache removeMemorySize: ' + value.source.getPixelBytesNumber() + ' currentMemory' + this.currentMemory)
} }
} }