-
Notifications
You must be signed in to change notification settings - Fork 0
Cache
Zachary Smith edited this page Apr 28, 2023
·
4 revisions
The user script is re-evaluated after each user interaction, to progress the script to the next input(), etc. This means expensive functions may be called more than once per session. To reduce latency, a cache decorator is made available through the python_web_io module. The @cache_to_file() decorator accepts a single argument: file_path, which indicates where the cache (a .pkl file) should be stored.
import python_web_io as io
@io.cache_to_file('cache.pickle')
def expensive_function(arg):
# Calculate the result here
return resultCache is persistent across sessions, allowing multiple users to access it. Session specific data can be stored using session from flask.
from flask import session
session['some_var] = 'some_val'Reserved keys for the session namespace are: io and counter.