Skip to content

Caching data between runs

Almenon edited this page Feb 9, 2020 · 6 revisions

Sometimes you might execute a lengthy query that you do not want to run again. Never fear, you can cache the result so it is saved inbetween runs! You have two options:

  1. use #$save (see readme)

  2. Using "arepl_store"

arepl_store is a variable that will hold data between runs.

If you assign a value to it and then comment that line out you can still reference that variable.

from time import sleep
from random import random

def longLastingFunction():
  sleep(5)
  return random()

x = longLastingFunction() # ugg takes forever each run
from time import sleep
from random import random

def longLastingFunction():
  sleep(5)
  return random()

arepl_store = longLastingFunction() # Instead I'll put it in my store
from time import sleep
from random import random

def longLastingFunction():
  sleep(5)
  return random()

# arepl_store = longLastingFunction() # comment this out - we don't want to call longLastingFunction twice!
print(arepl_store) # now I can get the function result without actually running the function!