Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Media caching #28

Merged
merged 3 commits into from
Apr 28, 2024
Merged

Media caching #28

merged 3 commits into from
Apr 28, 2024

Conversation

Vipitis
Copy link
Collaborator

@Vipitis Vipitis commented Apr 13, 2024

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
Copy link
Contributor

Korijn commented Apr 13, 2024

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
Copy link
Member

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
Copy link
Collaborator Author

Vipitis commented Apr 18, 2024

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.

@Vipitis Vipitis marked this pull request as ready for review April 27, 2024 21:59
@Vipitis Vipitis merged commit 11070dc into main Apr 28, 2024
11 checks passed
@Vipitis Vipitis deleted the cache-media branch April 28, 2024 00:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants