<commit_before>"""A full cache system written on top of Django's rudimentary one.

Frequently used functions are:
    cache_set(*keys, **kwargs)
    cache_get(*keys, **kwargs)
    cache_delete(*keys, **kwargs)
keys.. parameters of general type which are convertable to string or hashable unambiguously.
The keys can be of any general type which is convertable to string unambiguously or hashable.
Every unknown kwarg is interpreted like two aditional keys: (key, val).
Example:
    cache_set('product', 123, value=product)
    # is the same as
    cache_set('product::123', value=product)

More info below about parameters.
"""

from django.conf import settings
from django.core.cache import cache
from django.utils.encoding import smart_str
from django.utils.hashcompat import md5_constructor
from keyedcache.utils import is_string_like, is_list_or_tuple
import cPickle as pickle
import logging
import types

log = logging.getLogger('keyedcache')

# The debugging variable CACHED_KEYS is exact only with the the Django
# debugging server (or any single worker process server) and without restarting
# the server between restarts of the main cache (memcached).
# Keys in CACHED_KEYS variable never expire and can eat much memory on long
# running servers. Currently it is not confirmed in Satchmo.
# If more worker processes are used, the reported values of the following three
# variables can skip randomly upwards downwards.
CACHED_KEYS = {}
CACHE_CALLS = 0
CACHE_HITS = 0

KEY_DELIM = "::"
REQUEST_CACHE = {'enabled' : False}
try:
    CACHES = getattr(settings, "CACHES")
    CACHE_BACKEND = CACHES['default']['BACKEND']
    try:
        CACHE_PREFIX = CACHES['default']['KEY_PREFIX']
    except KeyError:
        CACHE_PREFIX = str(settings.SITE_ID)<commit_msg>Allow to choose what cache could be wrapped by keyedcache<commit_after>"""A full cache system written on top of Django's rudimentary one.

Frequently used functions are:
    cache_set(*keys, **kwargs)
    cache_get(*keys, **kwargs)
    cache_delete(*keys, **kwargs)
keys.. parameters of general type which are convertable to string or hashable unambiguously.
The keys can be of any general type which is convertable to string unambiguously or hashable.
Every unknown kwarg is interpreted like two aditional keys: (key, val).
Example:
    cache_set('product', 123, value=product)
    # is the same as
    cache_set('product::123', value=product)

More info below about parameters.
"""

from django.conf import settings
from django.core.cache.backends.base import InvalidCacheBackendError
from django.utils.encoding import smart_str
from django.utils.hashcompat import md5_constructor
from keyedcache.utils import is_string_like, is_list_or_tuple
import cPickle as pickle
import logging
import types

log = logging.getLogger('keyedcache')

# The debugging variable CACHED_KEYS is exact only with the the Django
# debugging server (or any single worker process server) and without restarting
# the server between restarts of the main cache (memcached).
# Keys in CACHED_KEYS variable never expire and can eat much memory on long
# running servers. Currently it is not confirmed in Satchmo.
# If more worker processes are used, the reported values of the following three
# variables can skip randomly upwards downwards.
CACHED_KEYS = {}
CACHE_CALLS = 0
CACHE_HITS = 0

KEY_DELIM = "::"
REQUEST_CACHE = {'enabled' : False}

try:
    from django.core.cache import get_cache
    cache_alias = getattr(settings, 'KEYEDCACHE_ALIAS', 'default')
    cache = get_cache(cache_alias)
except InvalidCacheBackendError:
    from django.core.cache import cache

try:
    CACHES = getattr(settings, "CACHES")
    CACHE_BACKEND = CACHES['default']['BACKEND']
    try:
        CACHE_PREFIX = CACHES['default']['KEY_PREFIX']
    except KeyError:
        CACHE_PREFIX = str(settings.SITE_ID)
{'fraction_non_alphanumeric': 0.07565875293503783, 'fraction_numerical': 0.004696060527002348, 'mean_word_length': 4.782805429864253, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '199603', 'n_tokens_mistral': 1115, 'n_tokens_neox': 1071, 'n_words': 427}