Compare commits

..

No commits in common. "17e3787cfa49107a7d5e9fb1d1365a15e2944de9" and "a1e8e0b15fd7033d72a71f9523ef148549b11ba3" have entirely different histories.

2 changed files with 13 additions and 14 deletions

View File

@ -1,7 +1,6 @@
## 3.2.1-rc.0 ## 3.2.1-rc.0
- Fix bug: CropTransformation is used to crop the original image - Fix bug: CropTransformation is used to crop the original image
- Fix bug: After calling the clear all file cache interfaces, the file cache becomes invalid - Fix bug: After calling the clear all file cache interfaces, the file cache becomes invalid
- Optimize the efficiency of file cache initialization.
## 3.2.0 ## 3.2.0
- When successfully requesting the network, return the httpcode as well - When successfully requesting the network, return the httpcode as well

View File

@ -70,7 +70,6 @@ export class FileCache {
interface CacheFileInfo { interface CacheFileInfo {
file: string; file: string;
ctime: number; ctime: number;
size: number;
} }
// 按照上次访问该文件的时间排序 // 按照上次访问该文件的时间排序
@ -79,25 +78,26 @@ export class FileCache {
let stat: fs.Stat | undefined = await FileUtils.getInstance().Stat(this.path + filenames[i]) let stat: fs.Stat | undefined = await FileUtils.getInstance().Stat(this.path + filenames[i])
cachefiles.push({ cachefiles.push({
file: filenames[i], file: filenames[i],
ctime: stat === undefined ? 0 : stat.ctime, ctime: stat === undefined ? 0 : stat.ctime
size: stat?.size ?? 0
}) })
} }
let sortedCachefiles: CacheFileInfo[] = cachefiles.sort((a, b) => a.ctime - b.ctime) let sortedCachefiles: CacheFileInfo[] = cachefiles.sort((a, b) => a.ctime - b.ctime)
for (let i = 0; i < sortedCachefiles.length; i++) { for (let i = 0; i < sortedCachefiles.length; i++) {
const fileSize: number = sortedCachefiles[i].size; let buf: ArrayBuffer | undefined = await FileUtils.getInstance().readFile(this.path + sortedCachefiles[i].file)
// 处理数量超过size的场景移除即将排除的文件 if (buf !== undefined) {
if (this.lruCache.length == this.maxSize && !this.lruCache.contains(sortedCachefiles[i].file)) { // 处理数量超过size的场景移除即将排除的文件
let remove: number | undefined = this.lruCache.remove(this.lruCache.keys()[0]) if (this.lruCache.length == this.maxSize && !this.lruCache.contains(sortedCachefiles[i].file)) {
if (remove !== undefined) { let remove: number | undefined = this.lruCache.remove(this.lruCache.keys()[0])
FileUtils.getInstance().deleteFile(this.path + this.lruCache.keys()[0]) if (remove !== undefined) {
this.removeMemorySize(fileSize) FileUtils.getInstance().deleteFile(this.path + this.lruCache.keys()[0])
this.removeMemorySize(buf)
}
} }
}
this.lruCache.put(sortedCachefiles[i].file, fileSize) this.lruCache.put(sortedCachefiles[i].file, buf.byteLength)
this.addMemorySize(fileSize) this.addMemorySize(buf)
}
} }
this.trimToSize(); this.trimToSize();