def test_expire_after(self):
# create mongo client
client = pymongo.MongoClient(host=settings.MONGO_HOST, port=settings.MONGO_PORT)
# init MongoItemPool with Mongo client
pool = MongoItemPool(client, DB="pycache", COLLECTION="pytest")
item = CacheItem()
# set expire
item.set("mykey", "myval")
item.expire_after(1)
pool.save(item)
ret_item = pool.get_item("mykey")
assert ret_item.is_hit() == True
time.sleep(2)
ret_item = pool.get_item("mykey")
assert ret_item.is_hit() == False
评论列表
文章目录