示例#1
0
    def call(self):
        cache = tiered_django_cache([
            ('locmem', self.memoize_timeout, get_locmem_prefix),
            ('default', self.timeout, get_default_prefix)
        ])

        return get_quickcache(
            cache=cache,
            vary_on=self.vary_on,
            skip_arg=self.skip_arg,
            assert_function=quickcache_soft_assert,
        ).call()
示例#2
0
    def set(self, key, value, timeout=None):
        super(CacheMock, self).set(key, value, timeout)
        if not self.silent_set:
            BUFFER.append('{} set'.format(self.name))


SHORT_TIME_UNIT = 0.01

_local_cache = CacheMock('local', timeout=SHORT_TIME_UNIT)
_shared_cache = CacheMock('shared', timeout=2 * SHORT_TIME_UNIT)
_cache = TieredCache([_local_cache, _shared_cache])
_cache_with_set = CacheMock('cache', timeout=SHORT_TIME_UNIT, silent_set=False)

quickcache = get_quickcache(cache=TieredCache(
    [CacheMock('local', timeout=10),
     CacheMock('shared', timeout=5 * 60)]))


class QuickcacheTest(TestCase):
    def tearDown(self):
        self.consume_buffer()

    def consume_buffer(self):
        result = list(BUFFER)
        del BUFFER[:]
        return result

    def test_tiered_cache(self):
        @quickcache([], cache=_cache)
        def simple():
示例#3
0
    def dst(self, dt):
        return datetime.timedelta(0)


SHORT_TIME_UNIT = 0.01

_local_cache = CacheMock('local', timeout=SHORT_TIME_UNIT)
_shared_cache = CacheMock('shared', timeout=2 * SHORT_TIME_UNIT)
_cache = TieredCache([_local_cache, _shared_cache])
_cache_with_set = CacheMock('cache', timeout=SHORT_TIME_UNIT, silent_set=False)

quickcache = get_quickcache(cache=TieredCache([
    CacheWithPresets(CacheMock('local', timeout=None),
                     timeout=10,
                     prefix_function=SessionMock.get_session),
    # even though CacheWithTimeout is deprecated, test it while it's still supported.
    CacheWithTimeout(CacheMock('shared', timeout=None), timeout=5 * 60)
]))


class QuickcacheTest(TestCase):
    def tearDown(self):
        self.consume_buffer()

    def consume_buffer(self):
        result = list(BUFFER)
        del BUFFER[:]
        return result

    def test_tiered_cache(self):