Пример #1
0
    def decorate(func):
        namespace = func_namespace(func, deco_args)
        skip_self = has_self_arg(func)
        regenerate = kwargs.get('regenerate', True)

        @wraps(func)
        def cached(*args):
            if region not in CacheRegion.regions:
                raise CacheConfigurationError(
                    'Cache region not configured: %s' % region)
            if not CacheRegion.enabled:
                return func(*args)

            if skip_self:
                try:
                    cache_key = " ".join(map(str, args[1:]))
                except UnicodeEncodeError:
                    cache_key = " ".join(map(str, args[1:]))
            else:
                try:
                    cache_key = " ".join(map(str, args))
                except UnicodeEncodeError:
                    cache_key = " ".join(map(str, args))

            def go():
                return func(*args)
            return CacheRegion.load(region, namespace, cache_key,
                                    regenerate=regenerate, callable=go)
        cached._region = region
        cached._namespace = namespace
        return cached
Пример #2
0
    def decorate(func):
        namespace = func_namespace(func, deco_args)
        skip_self = has_self_arg(func)
        regenerate = kwargs.get('regenerate', True)

        @wraps(func)
        def cached(*args):
            if region not in CacheRegion.regions:
                raise CacheConfigurationError(
                    'Cache region not configured: %s' % region)
            if not CacheRegion.enabled:
                return func(*args)

            if skip_self:
                try:
                    cache_key = " ".join(map(str, args[1:]))
                except UnicodeEncodeError:
                    cache_key = " ".join(map(unicode, args[1:]))
            else:
                try:
                    cache_key = " ".join(map(str, args))
                except UnicodeEncodeError:
                    cache_key = " ".join(map(unicode, args))

            def go():
                return func(*args)
            return CacheRegion.load(region, namespace, cache_key,
                                    regenerate=regenerate, callable=go)
        cached._region = region
        cached._namespace = namespace
        return cached
Пример #3
0
    def decorate(func):
        namespace = func_namespace(func, deco_args)
        skip_self = has_self_arg(func)
        regenerate = kwargs.get('regenerate', True)

        @wraps(func)
        def cached(*args, **kwargs):
            if region not in CacheRegion.regions:
                raise CacheConfigurationError(
                    'Cache region not configured: %s' % region)
            if not CacheRegion.enabled:
                return func(*args, **kwargs)
            cache_key = build_cache_key(skip_self, args, kwargs)
            def go():
                return func(*args, **kwargs)
            return CacheRegion.load(region, namespace, cache_key,
                                    regenerate=regenerate, callable=go)
        cached._region = region
        cached._namespace = namespace
        return cached
Пример #4
0
 def _makeKey(self, func, deco_args):
     from retools.util import func_namespace
     return func_namespace(func, deco_args)
Пример #5
0
 def _makeKey(self, func, deco_args):
     from retools.util import func_namespace
     return func_namespace(func, deco_args)