Best practice for refreshing indexdDB cache?

54 views
Skip to first unread message

ben...@gmail.com

unread,
Dec 15, 2022, 7:08:42 PM12/15/22
to brython
I'm a happy user of the indexedDB cache along with a custom brython_modules.js to speed up page loads.  It works brilliantly.  My new question is: when I update my python code, and build a new brython_modules.js, what is the best way to force a user's browser to dump the old indexedDB cache and reload from the server?  Should I just version the brython_modules.js filename?  Send and store a version field with each resource, and check it on each page load?

I'd love to hear your suggestions!

Thank you,
Ben

Pierre Quentel

unread,
Dec 16, 2022, 3:39:24 AM12/16/22
to brython
Hello Ben,

There should be nothing else to do other than update brython_modules.js (with the same name).

For each import, the Brython import engine checks if the module in brython_modules.js is the same as in the indexedDB cache (using timestamps); if not, the source code found in brython_modules.js is translated to Javascript, the result is stored in the cache and this version is used in the program.

Regards,
Pierre

 

ben levitt

unread,
Dec 16, 2022, 6:25:41 PM12/16/22
to bry...@googlegroups.com
Thank you Pierre!

I apologize for the noise.  I have a custom make_modules.py script that adds the full stdlib back into the carefully optimized set of necessary modules, so that my brython_modules.js will include the full stdlib, in case I need them in an exec() after compile time.  When adding all of the module keys back into the ModulesFinder's modules list, I was also accidentally adding the brython_stdlib.js file's $timestamp into the new brython_modules.js file, which was causing brython to not notice my changes to brython_modules.  I found and fixed this oversight of mine, and the automatic cache invalidation is working again!

I do still have a related issue, which is that it looks like my WebWorker is not making use of the indexedDB.  This is where most of my python code runs, so it would be very nice to use indexedDB in WebWorkers.  Were you expecting that to be working?

Thank you very much,
Ben


--
You received this message because you are subscribed to the Google Groups "brython" group.
To unsubscribe from this group and stop receiving emails from it, send an email to brython+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/brython/230a8b6b-0055-47eb-9368-798aa5adf1cbn%40googlegroups.com.

Shlomi Loubaton

unread,
Dec 31, 2022, 4:01:00 AM12/31/22
to brython
The WebWorker issue sound a lot like it might have something to do with this issue:
https://groups.google.com/g/brython/c/iDtJgGB55sg/m/jVFIUyODAAAJ
Seems like importing works in a different manner from WebWorkers.

Shlomi
Reply all
Reply to author
Forward
0 new messages