<commit_before>from django.core.cache import cache
from functools import wraps


NOT_IN_CACHE = object()


def cache_result(**cache_kwargs):
    """ Decorator to cache the result of a function call

    Usage

    @cache_result('myfunc', timeout=60)
    def my_function(a, b, c):
        pass
    """

    def _wrapper(f):

        @wraps(f)
        def _get(*args, **kwargs):

            name = f.__module__ + f.func_name
            key = create_key(name, args, kwargs)

            get_kwargs = dict(cache_kwargs)
            get_kwargs.pop('timeout')
            value = cache.get(key, NOT_IN_CACHE, **get_kwargs)

            if value is NOT_IN_CACHE:
                value = f(*args, **kwargs)

                cache.set(key, value, **cache_kwargs)<commit_msg>cache_result w/o "timeout" param<commit_after>from django.core.cache import cache
from functools import wraps


NOT_IN_CACHE = object()


def cache_result(**cache_kwargs):
    """ Decorator to cache the result of a function call

    Usage

    @cache_result('myfunc', timeout=60)
    def my_function(a, b, c):
        pass
    """

    def _wrapper(f):

        @wraps(f)
        def _get(*args, **kwargs):

            name = f.__module__ + f.func_name
            key = create_key(name, args, kwargs)

            # the timeout parameter can't be used when getting from a cache
            get_kwargs = dict(cache_kwargs)
            get_kwargs.pop('timeout', None)

            value = cache.get(key, NOT_IN_CACHE, **get_kwargs)

            if value is NOT_IN_CACHE:
                value = f(*args, **kwargs)

                cache.set(key, value, **cache_kwargs)
{'fraction_non_alphanumeric': 0.10635696821515893, 'fraction_numerical': 0.0024449877750611247, 'mean_word_length': 2.2287968441814594, 'pattern_counts': {'":': 0, '<': 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': '2918173', 'n_tokens_mistral': 519, 'n_tokens_neox': 487, 'n_words': 132}