def test_class_key_region():
    opts = {}
    opts['cache.regions'] = 'short_term'
    opts['cache.short_term.expire'] = '2'
    cache = make_cache_obj(**opts)

    class Foo(object):
        @cache_region('short_term', 'method')
        def go(self, x, y):
            return "hi foo"

    @cache_region('short_term', 'standalone')
    def go(x, y):
        return "hi standalone"

    x = Foo().go(1, 2)
    y = go(1, 2)
    ns = go._arg_namespace
    assert cache.get_cache_region(ns, 'short_term').get('method 1 2') == x
    assert cache.get_cache_region(ns, 'short_term').get('standalone 1 2') == y
Example #2
0
def test_class_key_region():
    opts = {}
    opts["cache.regions"] = "short_term"
    opts["cache.short_term.expire"] = "2"
    cache = make_cache_obj(**opts)

    class Foo(object):
        @cache_region("short_term", "method")
        def go(self, x, y):
            return "hi foo"

    @cache_region("short_term", "standalone")
    def go(x, y):
        return "hi standalone"

    x = Foo().go(1, 2)
    y = go(1, 2)
    ns = go._arg_namespace
    assert cache.get_cache_region(ns, "short_term").get("method 1 2") == x
    assert cache.get_cache_region(ns, "short_term").get("standalone 1 2") == y
Example #3
0
def test_class_key_region():
    opts = {}
    opts["cache.regions"] = "short_term"
    opts["cache.short_term.expire"] = "2"
    cache = make_cache_obj(**opts)

    class Foo(object):
        @cache_region("short_term", "method")
        def go(self, x, y):
            return "hi foo"

    @cache_region("short_term", "standalone")
    def go(x, y):
        return "hi standalone"

    x = Foo().go(1, 2)
    y = go(1, 2)
    ns = go._arg_namespace
    assert cache.get_cache_region(ns, "short_term").get("method 1 2") == x
    assert cache.get_cache_region(ns, "short_term").get("standalone 1 2") == y
def test_classmethod_key_region():
    opts = {}
    opts['cache.regions'] = 'short_term'
    opts['cache.short_term.expire'] = '2'
    cache = make_cache_obj(**opts)

    class Foo(object):
        @classmethod
        @cache_region('short_term', 'method')
        def go(cls, x, y):
            return "hi"

    x = Foo.go(1, 2)
    ns = Foo.go._arg_namespace
    assert cache.get_cache_region(ns, 'short_term').get('method 1 2') == x
Example #5
0
def test_classmethod_key_region():
    opts = {}
    opts["cache.regions"] = "short_term"
    opts["cache.short_term.expire"] = "2"
    cache = make_cache_obj(**opts)

    class Foo(object):
        @classmethod
        @cache_region("short_term", "method")
        def go(cls, x, y):
            return "hi"

    x = Foo.go(1, 2)
    ns = Foo.go._arg_namespace
    assert cache.get_cache_region(ns, "short_term").get("method 1 2") == x
Example #6
0
def test_classmethod_key_region():
    opts = {}
    opts["cache.regions"] = "short_term"
    opts["cache.short_term.expire"] = "2"
    cache = make_cache_obj(**opts)

    class Foo(object):
        @classmethod
        @cache_region("short_term", "method")
        def go(cls, x, y):
            return "hi"

    x = Foo.go(1, 2)
    ns = Foo.go._arg_namespace
    assert cache.get_cache_region(ns, "short_term").get("method 1 2") == x