~sirn/fanboi2

ref: baf63a21556905a6c27516a8d5641d31120d1fe3 fanboi2/fanboi2/cache.py -rw-r--r-- 618 bytes
baf63a21Kridsada Thanabulpong Add scope column to banwords. 1 year, 8 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import hashlib

from dogpile.cache import make_region


def key_mangler(key):
    """Retrieve cache keys as a long concatenated strings and turn them into
    an SHA256 hash.

    :param key: A cache key :type:`str`.
    """
    return hashlib.sha256(bytes(key.encode("utf8"))).hexdigest()


def includeme(config):  # pragma: no cover
    cache_region = make_region(key_mangler=key_mangler)
    cache_region.configure_from_config(config.registry.settings, "dogpile.")

    def cache_region_factory(context, request):
        return cache_region

    config.register_service_factory(cache_region_factory, name="cache")