CHRISTOPANANJICKAL / fast_cached_network_image

A flutter package to cache network image fastly without native dependencies.
MIT License
30 stars 36 forks source link

Cached image timestamps #51

Open TornadoStorm opened 7 months ago

TornadoStorm commented 7 months ago

Adding the ability to access the timestamp when an image was cached would enable the ability to implement custom cache invalidation techniques. For this, I request to add a method to get the timestamp when an image was cached, if it was cached.

My proposal is to simply add a static method: static Future<DateTime?> getCachedDate({required String imageUrl}), which returns the cached date, or null if no cached image is available. Looking at the package's source code, this should be fairly simple as the package already stores timestamps for cached files.

An example of a use case of this would be in an app where a widget displays an image from a Firebase Storage file, where the file could be updated externally at any time. Firebase storage does not currently have a way to notify the client when a file is updated, so a way to solve this would be to store an updatedAt timestamp in the file's metadata, so we just need to fetch the metadata of the file to access its timestamp. With the getCachedDate method, we can then compare our cached image's timestamp with the updatedAt timestamp of the file in the cloud, and invalidate our local cached image if it is outdated.