I would like to know what is the proper way of caching image and store it to Parse.com, and load it back, update cache etc.
So here is the scenario:
- I have a social network app where user can upload their profile picture.
- Once the user upload the picture. I believe we should cache the image in the device.
- User can also change their profile picture from the website.
My question is, If user update their profile picture. How could I detect the changes and update the cache? Image caching libraries detect from the URL. The problem is, the URL always stays the same.
So how do we know if the picture is already updated and re-download it to the device and replace the cache?
Thank you
You can
Set a validity period for the image cache. So image cache is reloaded with the latest data form server every, say, 24 hours or so.
Keep a 'timestamp' on your server whenever user uploads a profile picture and keep a local time stamp for every image URL on device when the image is cached. Check/compare time stamp on every app execution or every time the profile page is opened. When the server timestamp is newer, invalidate the cache and re-download the new image. Make sure local cache timestamp is updated every time the image is cached.
Maintain a file 'hash' string on the server. When you download the image file create a file hash locally and maintain it for every image URL. Compare local value to the server hash on every app execution or everytime the profile page is opened. If they are not the same, invalidate the cache and re-download the new image. Make sure local file hash is updated every time the file is downloaded. However, this will not be possible if your image caching module does not give you direct access to the downloaded physical file.
I assume you have clear idea of an image caching stratagy and hope this answers your question regarding 'how do we know if the picture is already updated and re-download it to the device and replace the cache?'.
If you want to know how to cache in image, you can use UIImage+AFNetworking.