Skip to content

Commit a87ae92

Browse files
committed
fix: cache improvements
1 parent c2bf9c0 commit a87ae92

File tree

3 files changed

+28
-9
lines changed

3 files changed

+28
-9
lines changed

src/image/index.android.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,11 @@ export class ImagePipeline {
130130
return android.net.Uri.parse(value);
131131
}
132132

133+
getCacheKey(uri: string, context) {
134+
// iOS only
135+
return uri;
136+
}
137+
133138
isInDiskCache(uri: string | android.net.Uri): boolean {
134139
return this._android.isInDiskCacheSync(this.toUri(uri));
135140
}

src/image/index.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,12 @@ export class ImagePipeline {
357357
*/
358358
isInBitmapMemoryCache(uri: string): boolean;
359359

360+
/**
361+
* Returns the actual cache key for url + context
362+
* this is an iOS feature because imageView properties are used for the cache key
363+
*/
364+
getCacheKey(uri: string, context): string;
365+
360366
/**
361367
* Returns whether the image is stored in the disk cache.
362368
*/

src/image/index.ios.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ export class ImagePipeline {
100100
private mIos: SDImageCache = SDImageCache.sharedImageCache;
101101
constructor() {}
102102

103+
getCacheKey(uri: string, context) {
104+
return SDWebImageManager.sharedManager.cacheKeyForURLContext(NSURL.URLWithString(uri), context);
105+
}
106+
103107
isInDiskCache(uri: string): boolean {
104108
return this.mIos.diskImageDataExistsWithKey(getUri(uri).absoluteString);
105109
}
@@ -117,7 +121,10 @@ export class ImagePipeline {
117121
}
118122

119123
evictFromCache(uri: string): void {
120-
this.mIos.removeImageForKeyWithCompletion(getUri(uri).absoluteString, null);
124+
const key = getUri(uri).absoluteString;
125+
this.mIos.removeImageFromDiskForKey(key);
126+
this.mIos.removeImageFromMemoryForKey(key);
127+
// this.mIos.removeImageForKeyWithCompletion(getUri(uri).absoluteString, null);
121128
}
122129

123130
clearCaches() {
@@ -401,17 +408,18 @@ export class Img extends ImageBase {
401408
}
402409

403410
const uri = getUri(src);
404-
if (this.noCache) {
405-
const key = uri.absoluteString;
406-
const imagePipeLine = getImagePipeline();
407-
const isInCache = imagePipeLine.isInBitmapMemoryCache(key);
408-
if (isInCache) {
409-
imagePipeLine.evictFromCache(key);
410-
}
411-
}
412411
this.isLoading = true;
413412
let options = SDWebImageOptions.ScaleDownLargeImages | SDWebImageOptions.AvoidAutoSetImage;
414413

414+
if (this.noCache) {
415+
// const key = uri.absoluteString;
416+
// const imagePipeLine = getImagePipeline();
417+
// const isInCache = imagePipeLine.isInBitmapMemoryCache(key);
418+
// if (isInCache) {
419+
// imagePipeLine.evictFromCache(key);
420+
// }
421+
options = options | SDWebImageOptions.FromLoaderOnly;
422+
}
415423
if (this.alwaysFade === true) {
416424
options |= SDWebImageOptions.ForceTransition;
417425
}

0 commit comments

Comments
 (0)