In [1]:
from time import sleep
from fito.operations.decorate import as_operation
@as_operation()
def expensive_computation(some_input):
print "Computing..."
sleep(1)
return 42
In [2]:
def execute(some_input):
op = expensive_computation(some_input)
print "About to execute: {}".format(op)
runner.execute(op)
print
In [3]:
# now expensive_computation is a subclass of Operation
expensive_computation(1)
Out[3]:
In [4]:
# create a data store with an execution FIFO cache of size 1
runner = OperationRunner(execute_cache_size=1)
# Hack to make it verbose, will improve that
runner.cache.verbose = True
In [5]:
# Will execute the operation
execute(1)
# Now it is in the cache
execute(1)
# Will execute the operation
# Will remove expensive_computation(1) from the cache
execute(2)
# Cache hit
execute(2)