def simple_function1(): return db_get(id=1)
def simple_function2(): return db_get(id=2)
def some_bigger_function(): return {"1": simple_function1(), "2": simple_function2(), "3": db_get(id=3)}
@cached('key1') def simple_function1(): return db_get(id=1) @cached('key2') def simple_function2(): return db_get(id=2) # SUPPOSE THIS IS IN ANOTHER MODULE @cached('big_key1') def some_bigger_function(): """ this function depends on big_key1, key1 and key2 """ def inner_workings(): db_set(1, 'something totally new') ####### ## imagine 100 lines of code here :) ###### inner_workings() return [simple_function1(),simple_function2()] if __name__ == '__main__': simple_function1() simple_function2() a,b = some_bigger_function() assert a == db_get(id=1), "this fails because we didn't invalidated cache properly"
@cached("key1") def simple_function1(): return db_get(id=1) @cached("key2") def simple_function2(): return db_get(id=2) # SUPPOSE THIS IS IN ANOTHER MODULE @cached("key") def some_bigger_function(): return {"1": simple_function1(), "2": simple_function2(), "3": db_get(id=3)} if __name__ == "__main__": simple_function1() # somewhere else db_set(1, "foobar") # and again db_set(3, "bazbar") invalidate("key") # ooops, we forgot something data = some_bigger_function() assert data["1"] == db_get(id=1), "this fails because we didn't manage to invalidate all the keys"