Invalidate Picasso cache remotely
I’m currently working on a commuter app (Madrid Metro|Bus|Cercanias) that allows you to browse among more than 1000 bus line maps (.png files). Obviously instead of shipping 500MB .png files within the apk I’m hosting these files on Amazon Simple Storage Service (aka Amazon S3) and the app just downloads and caches the images on the device upon user request thanks to the Picasso library for Android.
But what happens when any of these maps are replaced in S3 by a new version?
- When the map is not cached:
User requests map of line let’s say 123, Picasso checks its cache and as the .png is not there an internet request will be executed and the last version from S3 downloaded (and cached). Fine 🙂
- When the map is already cached:
User requests map of line 123, Picasso checks its cache and there is a .png file already cached, then it will be used directly without requesting the new one that is available at S3. User is seeing an old version. Terrible! :S