test_MongoAdapter.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:python-cache 作者: python-cache 项目源码 文件源码
def test_Decorator_expire(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, expire_after=0.5)
        def myAdder_expire(a, b):
            import time
            print 'Add %d + %d need 3 seconds!' % (a, b)
            time.sleep(3)
            return a + b

        assert myAdder_expire(5, 6) == 11  # wait for 3 seconds
        time.sleep(1)
        cur = time.time()
        assert myAdder_expire(5, 6) == 11  # need wait another 3 seconds
        assert time.time()-cur > 1
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号