I am building an application that can be used to load many large pictures. Once the pictures are loaded into the interface, it provides thumbnails of the larger images. The user can then interact with the images in various ways.
Now, these thumbnails are cached into ~/.cache/programname/
. This way, if the user attempts to reload the same pictures, the thumbnails are automatically picked and thus no resizing takes place. The large pictures take some time to be resized to thumbnail size, so I guess this is a legit technique.
I have limited the cache size to 12MB (around 5000 image thumbnails) but this adds complications:
- If user exceeds the 12MB limit, then my program will do something that he doesn't expect (aka starting mass deletion of files). User is not informed of the operation in any way.
- The deletion is done in that row: Delete thumbnails of pictures that do not belong in the current, selected by the user, folder (stop deleting pictures if sometime in-between cacheSize < 12MB), and if cacheSize is still >12MB delete some pictures that are in the selected folder till cacheSize < 12MB
- In order for me to be able to prioritize the deletion (aka see if a picture is in the current folder), I have to save the original picture filename, along with the md5sum of it into the thumbnail filename. BUT,
/
char is not allowed into filenames, so I used the ^ character instead. What if the filename/path of the original image already includes the ^ character? Implement a system inside the thumbnail's filename that specifies the ^ characters that should not be replaced.
All these complications, for a simple file, generate a filename such as:
47b29c689cc43f43de3ea3c7c68e4e3c=^usr^share^backgrounds^gnome^Road.jpg
When the file already contains the ^ character, the index(es) of the characters are saved in the filename:
47b29c689cc43f43de3ea3c7c68e4e3c=21.^home^alex^Pictures^1^1.png
My original thought when implementing this was to not eat up user space and it works just fine on doing that.
Now I am thinking about adding a 'Clear Cache' button in the Preferences dialog of my program and not care about space during the caching process. That would be simpler to implement, as saving just the md5sum of the image would be more than enough.
These are the options I have thought:
- Do not care about space. Use just the md5sum. 'Clear Cache' button.
- Current implementation: Care about space. User does not care about cache space as long as it doesn't eat up his whole hard drive, so have a set max value (12MB) and clear the cache selectively when cache exceeds that size.
- Care about space. User also cares about the amount of cache. Provide a slider and let user adjust how much space he wants to provide for the caching.
I think that solution 3 is not user-friendly, because the average user does not need to know what cache is. But, using the same logic, the average user does not know what the 'Clear Cache' button is; he just wants the program to load fast - and that's what cache does.
That's why I chose solution 2, but it has the disadvantage of doing actions without user consent.
What are your opinions on the issue?