Skip to content

Commit

Permalink
Feature: Add clear image cache from memory and disk
Browse files Browse the repository at this point in the history
  • Loading branch information
guhungry committed Mar 9, 2019
1 parent 89c0e2e commit 2b79960
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 1 deletion.
Expand Up @@ -53,4 +53,25 @@ public void run() {
}
});
}

@ReactMethod
public void clearMemoryCache() {
final Activity activity = getCurrentActivity();
if (activity == null) return;

activity.runOnUiThread(new Runnable() {
@Override
public void run() {
Glide.get(activity.getApplicationContext()).clearMemory();
}
});
}

@ReactMethod
public void clearDiskCache() {
final Activity activity = getCurrentActivity();
if (activity == null) return;

Glide.get(activity.getApplicationContext()).clearDiskCache();
}
}
12 changes: 11 additions & 1 deletion ios/FastImage/FFFastImageViewManager.m
@@ -1,6 +1,7 @@
#import "FFFastImageViewManager.h"
#import "FFFastImageView.h"

#import <SDWebImage/SDImageCache.h>
#import <SDWebImage/SDWebImagePrefetcher.h>

@implementation FFFastImageViewManager
Expand Down Expand Up @@ -33,5 +34,14 @@ - (FFFastImageView*)view {
[[SDWebImagePrefetcher sharedImagePrefetcher] prefetchURLs:urls];
}

@end
RCT_EXPORT_METHOD(clearMemoryCache)
{
[SDImageCache.sharedImageCache clearMemory];
}

RCT_EXPORT_METHOD(clearDiskCache)
{
[SDImageCache.sharedImageCache clearDiskOnCompletion:^(){}];
}

@end
2 changes: 2 additions & 0 deletions src/index.d.ts
Expand Up @@ -137,6 +137,8 @@ interface FastImageStatic extends React.ComponentClass<FastImageProperties> {
}

preload(sources: FastImageSource[]): void
clearMemoryCache(): void
clearDiskCache(): void
}

declare var FastImage: FastImageStatic
Expand Down
12 changes: 12 additions & 0 deletions src/index.js
Expand Up @@ -102,6 +102,18 @@ FastImage.preload = sources => {
FastImageViewNativeModule.preload(sources)
}

FastImage.clearMemoryCache = () => {
FastImageViewNativeModule.clearMemoryCache()
}

FastImage.clearDiskCache = () => {
FastImageViewNativeModule.clearDiskCache()
}

FastImage.defaultProps = {
resizeMode: FastImage.resizeMode.cover,
}

FastImage.defaultProps = {
resizeMode: FastImage.resizeMode.cover,
}
Expand Down
2 changes: 2 additions & 0 deletions src/index.js.flow
Expand Up @@ -68,4 +68,6 @@ declare export default class FastImage extends React$Component<FastImageProps> {
static priority: Priority;
static cacheControl: CacheControl;
static preload: PreloadFn;
static clearMemoryCache: () => void;
static clearDiskCache: () => void;
}

0 comments on commit 2b79960

Please sign in to comment.