Esempio n. 1
0
    def test_put_clear(self):
        ctrl = CacheCtrl(cache_stores=[RamCacheStore(), DiskCacheStore()])

        # put and check has
        ctrl.put(NODE, 10, "key")
        assert ctrl.has(NODE, "key")

        # clear and check has
        ctrl.clear()

        # check has
        assert not ctrl.has(NODE, "key")
Esempio n. 2
0
    def test_invalid_mode(self):
        ctrl = CacheCtrl(cache_stores=[RamCacheStore(), DiskCacheStore()])

        with pytest.raises(ValueError, match="Invalid mode"):
            ctrl.put(NODE, 10, "key", mode="other")

        with pytest.raises(ValueError, match="Invalid mode"):
            ctrl.get(NODE, "key", mode="other")

        with pytest.raises(ValueError, match="Invalid mode"):
            ctrl.has(NODE, "key", mode="other")

        with pytest.raises(ValueError, match="Invalid mode"):
            ctrl.rem(NODE, "key", mode="other")

        with pytest.raises(ValueError, match="Invalid mode"):
            ctrl.clear(mode="other")
Esempio n. 3
0
    def test_put_has_mode(self):
        ctrl = CacheCtrl(cache_stores=[RamCacheStore(), DiskCacheStore()])

        # put disk and check has
        assert not ctrl.has(NODE, "key")

        ctrl.put(NODE, 10, "key", mode="disk")
        assert not ctrl._cache_stores[0].has(NODE, "key")
        assert not ctrl.has(NODE, "key", mode="ram")
        assert ctrl._cache_stores[1].has(NODE, "key")
        assert ctrl.has(NODE, "key", mode="disk")
        assert ctrl.has(NODE, "key")

        # put ram and check has
        ctrl.clear()
        assert not ctrl.has(NODE, "key")

        ctrl.put(NODE, 10, "key", mode="ram")
        assert ctrl._cache_stores[0].has(NODE, "key")
        assert ctrl.has(NODE, "key", mode="ram")
        assert not ctrl._cache_stores[1].has(NODE, "key")
        assert not ctrl.has(NODE, "key", mode="disk")
        assert ctrl.has(NODE, "key")