How to have independent cache in spaces

I want to have a cache for each user doing a task, their particular cache is retained so that if the same user is using the service then, the process is fastened. The cache is then deleted upon completion.

1 Like

Maybe it’s done by default in HF Spaces, but do you want to implement some additional cache, something like lru_cache?

I think I framed my question incorrectly, the issue is that I wanna have a local variable store the results worked to speed up the process with the same but I found out that local variable isn’t actually exclusive of the person who is using it and hence, doesn’t permit mutual exclusion.

I think it’s basically saved per user instance, except for file-related and special functions and variables like pipelines and environment variables.
It may change a bit depending on the settings when Gradio is started, though. Maybe you’re running into some weird bug?

Here’s my implementation: need global otherwise it won’t persist through another function call

1 Like

I see that global variables are shared.
How about using gr.State() or gr.JSON() to manage variables?
Or you could use uuid as a key and create a dict and store variables for each user in it.

Thanks a lot! I didn’t know Gradio had States similar to React

1 Like

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.