def test_Decorator(self):
client = pymongo.MongoClient(host=settings.MONGO_HOST, port=settings.MONGO_PORT)
pool = MongoItemPool(client, DB="pycache", COLLECTION="pytest")
# decorate myAdder function in common way
@cached(CacheItemPool=pool)
def myAdder(a, b):
import time
print 'Add %d + %d need 3 seconds!' % (a, b)
time.sleep(3)
return a + b
assert myAdder(5, 6) == 11 # wait for 3 seconds
assert myAdder(5, 6) == 11 # no need wait
评论列表
文章目录