コード例 #1
0
def test_caching(cache_type):
    key = CacheKey("foo", "60m")
    cache = cache_type(TEST_CACHE_CONFIG)

    # Perform two retrievals, and make sure both return.
    assert cache.retrieve(key, lambda: {"a": 1234}) == {"a": 1234}
    assert cache.retrieve(key, lambda: {"a": 1234}) == {"a": 1234}
コード例 #2
0
ファイル: test_cache.py プロジェクト: BillDett/quay
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
ファイル: test_cache.py プロジェクト: quay/quay
def test_redis_cache():
    global DATA
    DATA = {}

    redis_config = {
        "primary": {
            "host": "127.0.0.1",
            "port": 6279,
            "db": 0,
            "password": "",
            "ssl": False,
            "ssl_ca_certs": None,
        },
        "replica": {
            "host": "127.0.0.1",
            "port": 6279,
            "db": 0,
            "password": "",
            "ssl": False,
            "ssl_ca_certs": None,
        },
    }

    key = CacheKey("foo", "60m")
    with patch("data.cache.impl.StrictRedis", MockClient):
        cache = RedisDataModelCache(TEST_CACHE_CONFIG,
                                    redis_config.get("primary"),
                                    redis_config.get("replica"))

        assert cache.retrieve(key, lambda: {"a": 1234}) == {"a": 1234}
        assert cache.retrieve(key, lambda: {"a": 1234}) == {"a": 1234}
コード例 #4
0
def test_caching(cache_type):
    key = CacheKey('foo', '60m')
    cache = cache_type()

    # Perform two retrievals, and make sure both return.
    assert cache.retrieve(key, lambda: {'a': 1234}) == {'a': 1234}
    assert cache.retrieve(key, lambda: {'a': 1234}) == {'a': 1234}
コード例 #5
0
def test_redis_cache():
    global DATA
    DATA = {}

    key = CacheKey("foo", "60m")
    cache = RedisDataModelCache(TEST_CACHE_CONFIG, MockClient())

    assert cache.retrieve(key, lambda: {"a": 1234}) == {"a": 1234}
    assert cache.retrieve(key, lambda: {"a": 1234}) == {"a": 1234}
コード例 #6
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}
コード例 #7
0
def test_redis_cache():
    global DATA
    DATA = {}

    key = CacheKey("foo", "60m")
    with patch("data.cache.impl.StrictRedis", MockClient):
        cache = RedisDataModelCache("127.0.0.1")

        assert cache.retrieve(key, lambda: {"a": 1234}) == {"a": 1234}
        assert cache.retrieve(key, lambda: {"a": 1234}) == {"a": 1234}
コード例 #8
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
        }
コード例 #9
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}
コード例 #10
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}