pegasus-frontend
pegasus-frontend copied to clipboard
Cache images in themes
Currently the default theme does not seem to cache images. So if we have hundreds of games, the disk is accessed for each image as we scroll through. If the media is stored on a slow network drive, this causes a noticeable impact on how quickly the images load as we scroll. Worse, if the media is fetched via http, we are fetching the same images over and over as we scroll up and down.
We should see if there is a way to cache these images in memory and/or disk. In my particular use case, I want to be able to fetch media from http. It works quite well except for the caching.
Below is an example of http image loading demonstrating the lack of cache:
https://user-images.githubusercontent.com/302882/140615576-94c77df9-737d-4e6d-af4b-34f719ad013e.mp4
The images are cached, for both the network traffic part (you should be able to see the files under ~/.cache/pegasus-frontend/netcache/) and for displaying (as far as I know, depending on the VRAM and the QML View configuration). The actual implementation is handled by Qt though, so not sure how much we can affect that. In this particular case, perhaps the list could be fine tuned to allow more elements in the memory.
Yeah I looked into this and Qt does have a cache which is on by default, but I can confirm that when fetching http images the same calls are still being made over and over. I have read that the cache size is not adjustable and has a 2MB limit, but not sure.
I did some more testing, caching does appear to work for a small number of images, but it seems to have a limit and that's where the problem is. Also I'm still not sure if Qt does any disk caching of images by default. I think it's just in-memory.
Yes, I've added on-disk cache (see https://doc.qt.io/qt-5/qnetworkdiskcache.html). It has the default size of 50 MB, which matches the directory size I have locally. Do you see a different result?
Also, I was thinking about the repeated image fetching, do you see a full re-download of the image, or just queries about whether the image is up to date (eg. Etag or other cache-related HTTP headers)? Perhaps the server tells that the images shouldn't be cached?
Oh, sweet. I'll try adjusting the disk cache size then and see what happens.
Right now yes, it re-downloads some of the images if there are too many.
I'm definitely downloading more than 50MB of images so that's probably the issue.
Adjusting the disk cache to 1000 MB worked. I guess there's not really a bug here necessarily. 50MB might be a bit too small of a disk cache for a Windows machine, but my use case is kind of rare so 🤷
@polson well could you point me to the var where you set the cache size to 1000MB?