What I’m trying to do:
I would like to load a large file into memory from the Files datatable once, and then have it retrieved in memory every time the main function runs.
What I’ve tried and what’s not working:
Currently I am calling another function which loads the files into memory with each trigger. I have not been able to figure out how to maintain the files in memory and access them as needed.
Code Sample:
# this is a formatted code snippet.
# paste your code between ```
Clone link:
share a copy of your app
You need to enable the persistent server option, available only on some higher level plans. The global variable would persist across multiple requests, but there are still reasons why the server could restart and the global variables could be lost. So you will be lucky most of the times, but you may have some slow responses once in a while.
The free and lower level plans don’t allow persistent server. With every request they spin a new instance of python, hence they regenerate all the global variables.
1 Like
Whose memory: the Server’s, or the Browser’s?
1 Like
I meant the Server memory. I.e, loaded a Machine Learning model into memory as variable X. I have persistent server activated. When a new session is started, how can I access Variable X from code? Would I just reference it directly as if I had loaded it in the current runtime?
I just skimmed the Persistent Server documentation, and it didn’t tell me whether it was one Persistent Server Instance per App, or per App Client. It looks like you’re assuming Per App.
I’ll leave that question to the folks here with actual Persistent Server experience.
1 Like
Any global variable of a server module, if you are lucky (and 90%+ of times you will be lucky), will persist across calls if you use persistent server.
Just make sure that those global variables are only used in read only mode, because there could be multiple requests concurrently accessing the same data, and you don’t want them to step on each other toes.
1 Like