# -*- coding: utf-8 -*-
from dogpile.cache.region import make_region

_regions = {}


def init_region(conf, region=None):
    """
    Initialize the caching module.
    """
    cache_region = make_region()
    kwargs = dict((k, conf[k])
            for k in ('arguments', 'expiration_time') if k in conf)
    cache_region.configure(conf['backend'], **kwargs)
    _regions[region] = cache_region
    return cache_region


def get_region(region=None):
    """
    Return a cache region.
    """
    try:
        return _regions[region]
    except KeyError:
        raise Exception("No such caching region. A region must be"
                "initialized before it can be used")


def invalidate_region(region=None):
    return get_region(region).invalidate()

@@ -17,16 +17,65 @@
 f-8 -*-%0A
+import inspect%0A%0Afrom dogpile.cache import compat%0A
 from dog
@@ -128,16 +128,1057 @@
  = %7B%7D%0A%0A%0A
+def keygen_function(namespace, fn):%0A    %22%22%22Return a function that generates a string%0A    key, based on a given function as well as%0A    arguments to the returned function itself.%0A%0A    This is used by :meth:%60.CacheRegion.cache_on_arguments%60%0A    to generate a cache key from a decorated function.%0A    %22%22%22%0A%0A    if namespace is None:%0A        namespace = '%25s:%25s' %25 (fn.__module__, fn.__name__)%0A    else:%0A        namespace = '%25s:%25s%7C%25s' %25 (fn.__module__, fn.__name__, namespace)%0A%0A    args = inspect.getargspec(fn)%0A    has_self = args%5B0%5D and args%5B0%5D%5B0%5D in ('self', 'cls')%0A%0A    def generate_key(*args, **kw):%0A        if kw:%0A            raise ValueError(%0A                    %22key creation function does not accept keyword arguments.%22)%0A        parts = %5Bnamespace%5D%0A        if has_self:%0A            self_ = args%5B0%5D%0A            if hasattr(self_, 'request'):%0A                parts.append(self_.request.host_url)%0A            args = args%5B1:%5D%0A        parts.append(%22 %22.join(map(compat.text_type, args)))%0A        return %22%7C%22.join(parts)%0A    return generate_key%0A%0A%0A
 def init
@@ -1252,24 +1252,24 @@
 le.%0A    %22%22%22%0A
-
     cache_re
@@ -1287,16 +1287,54 @@
 _region(
+function_key_generator=keygen_function
 )%0A    kw

introduce keygen_function to generate different cache keys by host url