Example #1
0
def test_as_cached_key_only():
    def test_fn(i=[0]):
        i[0] += 1
        return i[0]

    assert state.as_cached('test', test_fn) == 1
    assert state.as_cached('test', test_fn) == 1
Example #2
0
def test_as_cached_ttl():
    def test_fn(i=[0]):
        i[0] += 1
        return i[0]

    assert state.as_cached('test', test_fn, ttl=0.1) == 1
    time.sleep(0.11)
    assert state.as_cached('test', test_fn, ttl=0.1) == 2
Example #3
0
def test_as_cached_key_and_kwarg():
    def test_fn(a, i=[0]):
        i[0] += 1
        return i[0]

    assert state.as_cached('test', test_fn, a=1) == 1
    assert state.as_cached('test', test_fn, a=1) == 1
    assert state.as_cached('test', test_fn, a=2) == 2
    assert state.as_cached('test', test_fn, a=1) == 1
    assert state.as_cached('test', test_fn, a=2) == 2
def test_as_cached_key_only():
    global i
    i = 0

    def test_fn():
        global i
        i += 1
        return i

    assert state.as_cached('test', test_fn) == 1
    assert state.as_cached('test', test_fn) == 1
    state.cache.clear()
def test_as_cached_key_and_kwarg():
    global i
    i = 0

    def test_fn(a):
        global i
        i += 1
        return i

    assert state.as_cached('test', test_fn, a=1) == 1
    assert state.as_cached('test', test_fn, a=1) == 1
    assert state.as_cached('test', test_fn, a=2) == 2
    assert state.as_cached('test', test_fn, a=1) == 1
    assert state.as_cached('test', test_fn, a=2) == 2
    state.cache.clear()