How to use the pottery.cache.CacheInfo function in pottery

To help you get started, we’ve selected a few pottery examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github brainix / pottery / tests / test_cache.py View on Github external
def test_wrapped(self):
        value1 = self.expensive_method_expiration()
        assert self.expensive_method_expiration() == value1
        assert self.expensive_method_expiration.cache_info() == CacheInfo(
            hits=1,
            misses=1,
            maxsize=None,
            currsize=1,
        )

        value2 = self.expensive_method_expiration.__wrapped__()
        assert value2 != value1
        assert self.expensive_method_expiration.cache_info() == CacheInfo(
            hits=1,
            misses=1,
            maxsize=None,
            currsize=1,
        )

        assert self.expensive_method_expiration() == value1
        assert self.expensive_method_expiration.cache_info() == CacheInfo(
            hits=2,
            misses=1,
            maxsize=None,
            currsize=1,
        )
github brainix / pottery / tests / test_cache.py View on Github external
def test_bypass(self, getrandbits):
        getrandbits.return_value = 5

        self.expensive_method_expiration()
        assert getrandbits.call_count == 1
        assert self.expensive_method_expiration.cache_info() == CacheInfo(
            hits=0,
            misses=1,
            maxsize=None,
            currsize=1,
        )

        self.expensive_method_expiration()
        assert getrandbits.call_count == 1
        assert self.expensive_method_expiration.cache_info() == CacheInfo(
            hits=1,
            misses=1,
            maxsize=None,
            currsize=1,
        )

        self.expensive_method_expiration.__bypass__()
github brainix / pottery / tests / test_cache.py View on Github external
def test_cache_clear(self):
        self.expensive_method_expiration()
        assert self.expensive_method_expiration.cache_info() == CacheInfo(
            hits=0,
            misses=1,
            maxsize=None,
            currsize=1,
        )

        self.expensive_method_expiration.cache_clear()
        assert self.expensive_method_expiration.cache_info() == CacheInfo(
            hits=0,
            misses=0,
            maxsize=None,
            currsize=0,
        )

        self.expensive_method_expiration()
        self.expensive_method_expiration()
        self.expensive_method_expiration('raj')
        assert self.expensive_method_expiration.cache_info() == CacheInfo(
            hits=1,
            misses=2,
            maxsize=None,
            currsize=2,
        )
github brainix / pottery / tests / test_cache.py View on Github external
hits=1,
            misses=2,
            maxsize=None,
            currsize=2,
        )
        assert value2 != value1
        assert self.expensive_method_expiration('raj') == value2
        assert self.expensive_method_expiration.cache_info() == CacheInfo(
            hits=2,
            misses=2,
            maxsize=None,
            currsize=2,
        )

        value3 = self.expensive_method_expiration(first='raj', last='shah')
        assert self.expensive_method_expiration.cache_info() == CacheInfo(
            hits=2,
            misses=3,
            maxsize=None,
            currsize=3,
        )
        assert value3 != value1
        assert value3 != value2
        assert self.expensive_method_expiration(first='raj', last='shah') == value3
        assert self.expensive_method_expiration.cache_info() == CacheInfo(
            hits=3,
            misses=3,
            maxsize=None,
            currsize=3,
        )

        value4 = self.expensive_method_expiration(last='shah', first='raj')