Image caching best practice for unique identifier

280 views Asked by At

I am trying to build an app where I download a list of images from different URLs into a collection view. All these images are stored inside a cache with max age and cache limit. I am storing the URL as the key for each image so that I can check if the image already exists when downloading it again and if yes, check the max age, but I have been told that storing URLs as ID is bad practice. Any suggestions on how I could save these images and retrieve their details when needed?

1

There are 1 answers

0
user2712678 On

So to be clear were thinking a good way to store info about an image is instead of having an object like this :

"some_url_as_the_key":{ // details about the image }

we could have.

"number_of_bytes_of_the_image_as_key":{ //detail about the image }

Im trying to do the same and need to store the meta data bout each image in a dictionary. Which of the above would be best. I can see an issue in as much as two images could theoretically have the same number of bytes, though 1) this is unlikely, and 2) would possibly be a faster look up when searching for the meta data about an image that i need to store. I.e. a key of '12312423' (number of bytes), vs a long url like "https://www.lindofinasdoifnosidnf.sdfsdfnsdf/dfsdf' would be faster i guess.

Thoughts?