我想在Django缓存中保存一些值并将跟踪函数绑定到它,所以一旦值改变,我想调用一个函数。在调用跟踪函数后,我想删除绑定。
from django.core.cache import cache
cache.set("MyVariable", value, None)
cache.get("MyVariable")
def callbackFunction():
print cache.get("MyVariable")
cache.unbind("MyVariable", callbackFunction)
def runOnce():
cache.bind("MyVariable", callbackFunction) # Bind Cache Variable
runOnce()
cache.set("MyVariable", 123, None)
cache.set("MyVariable", 999, None)
预期打印结果:
123