pygfx / shadertoy

Shadertoy implementation based on wgpu-py
BSD 2-Clause "Simplified" License
10 stars 0 forks source link

Media caching #28

Closed Vipitis closed 2 months ago

Vipitis commented 2 months ago

This was mentioned in #25

Main idea is to avoid downloading the same media (currently just images, maybe additional resources later) over and over again. Should speed things up and avoid duplicate requests. Media isn't included in the repo, it's build dynamically. The website only offers a quite limited number of default media. Perhaps there could be an init function to grab all of it instead.

This implementation is really crude, as media is cached to a folder in the library, which I don't think is the proper solution. I will look at some other examples.

Korijn commented 2 months ago

Commonly used location would be:

Unix ~/.cache/shadertoy (or $XDG_CACHE_HOME/shadertoy if set)

macOS ~/Library/Caches/shadertoy

Windows %LOCALAPPDATA%\shadertoy\Cache

This mirrors what tools like pip and poetry use

almarklein commented 2 months ago

Imageio has a similar utility. Here's the code that does the downloading: https://github.com/imageio/imageio/blob/master/imageio/core/fetching.py. It uses a progress-bar (implemented here), which may be a bit much for this use-case, but perhaps it can serve as inspiration, especially regarding edge-cases like the local file being in use (on Windows), etc.

Vipitis commented 2 months ago

I took some additional inspiration from pygfx. There might be some edge cases - not sure where those will be encountered. I am also not able to test OS X myself.