示例#1
0
def test_memcache():
    global DATA
    DATA = {}

    key = CacheKey("foo", "60m")
    with patch("data.cache.impl.PooledClient", MockClient):
        cache = MemcachedModelCache(TEST_CACHE_CONFIG, ("127.0.0.1", "-1"))
        assert cache.retrieve(key, lambda: {"a": 1234}) == {"a": 1234}
        assert cache.retrieve(key, lambda: {"a": 1234}) == {"a": 1234}
示例#2
0
def test_memcache_should_cache():
    global DATA
    DATA = {}

    key = CacheKey("foo", None)

    def sc(value):
        return value["a"] != 1234

    with patch("data.cache.impl.PooledClient", MockClient):
        cache = MemcachedModelCache(TEST_CACHE_CONFIG, ("127.0.0.1", "-1"))
        assert cache.retrieve(key, lambda: {"a": 1234}, should_cache=sc) == {
            "a": 1234
        }

        # Ensure not cached since it was `1234`.
        assert cache._get_client_pool().get(key.key) is None

        # Ensure cached.
        assert cache.retrieve(key, lambda: {"a": 2345}, should_cache=sc) == {
            "a": 2345
        }
        assert cache._get_client_pool().get(key.key) is not None
        assert cache.retrieve(key, lambda: {"a": 2345}, should_cache=sc) == {
            "a": 2345
        }
示例#3
0
def test_memcache_should_cache():
    key = CacheKey('foo', None)

    def sc(value):
        return value['a'] != 1234

    with patch('data.cache.impl.Client', MockClient):
        cache = MemcachedModelCache(('127.0.0.1', '-1'))
        assert cache.retrieve(key, lambda: {'a': 1234}, should_cache=sc) == {
            'a': 1234
        }

        # Ensure not cached since it was `1234`.
        assert cache._get_client().get(key.key) is None

        # Ensure cached.
        assert cache.retrieve(key, lambda: {'a': 2345}, should_cache=sc) == {
            'a': 2345
        }
        assert cache._get_client().get(key.key) is not None
        assert cache.retrieve(key, lambda: {'a': 2345}, should_cache=sc) == {
            'a': 2345
        }
示例#4
0
def test_memcache():
    key = CacheKey('foo', '60m')
    with patch('data.cache.impl.Client', MockClient):
        cache = MemcachedModelCache(('127.0.0.1', '-1'))
        assert cache.retrieve(key, lambda: {'a': 1234}) == {'a': 1234}
        assert cache.retrieve(key, lambda: {'a': 1234}) == {'a': 1234}
示例#5
0
def test_memcache():
    key = CacheKey("foo", "60m")
    with patch("data.cache.impl.Client", MockClient):
        cache = MemcachedModelCache(("127.0.0.1", "-1"))
        assert cache.retrieve(key, lambda: {"a": 1234}) == {"a": 1234}
        assert cache.retrieve(key, lambda: {"a": 1234}) == {"a": 1234}