<commit_before>"""
Caching utilities
"""
import json

from flask import current_app

from werkzeug.contrib.cache import RedisCache


def get_redis():
    if not hasattr(current_app, 'redis'):
        host, port = current_app.config["REDIS_CONN"]
        cache = RedisCache(host, port)

        current_app.redis = cache

    return current_app.redis


def get_cached_user_data(token):
    # Gets cached user data.
    r = get_redis()
    key = "user" + json.dumps(token, sort_keys=True)
    d = r.get(key)
    if d:
        return json.loads(d)


def set_cached_user_data(token, data, expiration=300):
    r = get_redis()
    key = "user" + json.dumps(token, sort_keys=True)
    r.set(key, json.dumps(data), timeout=expiration)
    return data

<commit_msg>Use default_timeout for futureproofing<commit_after>"""
Caching utilities
"""
import json

from flask import current_app

from werkzeug.contrib.cache import RedisCache


def get_redis():
    if not hasattr(current_app, 'redis'):
        host, port = current_app.config["REDIS_CONN"]
        cache = RedisCache(host, port, default_timeout=300)

        current_app.redis = cache

    return current_app.redis


def get_cached_user_data(token):
    # Gets cached user data.
    r = get_redis()
    key = "user" + json.dumps(token, sort_keys=True)
    d = r.get(key)
    if d:
        return json.loads(d)


def set_cached_user_data(token, data, expiration=300):
    r = get_redis()
    key = "user" + json.dumps(token, sort_keys=True)
    r.set(key, json.dumps(data), timeout=expiration)
    return data


{'fraction_non_alphanumeric': 0.11153846153846154, 'fraction_numerical': 0.0057692307692307696, 'mean_word_length': 3.4472934472934473, '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': '3989451', 'n_tokens_mistral': 560, 'n_tokens_neox': 540, 'n_words': 128}