Esempio n. 1
0
def test_cache_copy(cache: Cache):
    """Test that cache.copy() returns a copy of the cache."""
    items = {"a": 1, "b": 2, "c": 3}
    cache.set_many(items)

    copied = cache.copy()
    assert copied == items
    assert copied is not cache._cache
Esempio n. 2
0

# 异步生成器
@cache.memoize()
async def func(a, b):
    return a + b


@cache.memoize()
def func(a, b):
    pass


func.uncached(1, 2)

assert cache.copy() == {1: "foobar", 2: ("foo", "bar", "baz")}

cache.delete(1)
assert cache.get(1) is None

cache.clear()
assert len(cache) == 0

cache.set_many({"a": 1, "b": 2, "c": 3})
assert cache.get_many(["a", "b", "c"]) == {"a": 1, "b": 2, "c": 3}
cache.delete_many(["a", "b", "c"])
assert cache.count() == 0

import re

cache.set_many({"a_1": 1, "a_2": 2, "123": 3, "b": 4})