how to expire cached nimbus network image
-
12-06-2021 - |
문제
I'm having trouble with refreshing a nimbus image and not sure if I'm correctly removing the cached images. After I upload a new image it still keeps showing the old image on refresh for a few minutes or more.
[(SDURLCache*)[NSURLCache sharedURLCache] removeCachedResponseForRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]]];
[[Nimbus imageMemoryCache] removeObjectWithName:url];
[profilePic setPathToNetworkImage:url];
Which way is the right way to remove the cache?
해결책
I've added a new method to Nimbus' in-memory cache called removeAllObjectsWithPrefix:
. You can use this method in the following way to forcefully expire images from the cache:
[imageView.imageMemoryCache removeAllObjectsWithPrefix:imageUrl];
You will need to know the url in order to expire it from the cache.
The reason why this method is necessary is because NINetworkImageView adds a suffix to the image cache key to differentiate between different sizes and content modes.
https://github.com/jverkoey/nimbus/blob/master/src/networkimage/src/NINetworkImageView.m#L137