<commit_before># coding:UTF-8


"""
缓存模块
@author:yubang
"""


from django.core.cache.backends.base import BaseCache
import sae.kvdb


class SaeKVCache(BaseCache):
    """基于sae的django缓存模块"""
    def __init__(self, server, param):
        self.timeout = param.get('timeout', 1800)
        self.key_prefix = param.get('key_prefix', 'windPlug')
        self.__cache = sae.kvdb.Client()

    def __del__(self):
        pass

    def make_key(self, key, version=None):
        if version is None:
            version = 'default'
        else:
            version = str(version)
        return '_'.join((self.key_prefix, version, key))

    def has_key(self, key, version=None):
        return self.__cache.get(self.make_key(key, version)) is not None

    def set(self, key, value, timeout=None, version=None):
        if timeout is None:
            timeout = self.timeout
        self.__cache.expire(self.make_key(key, version), timeout)
        return self.__cache.set(self.make_key(key, version), value)

    def get(self, key, default=None, version=None):
        return self.__cache.get(self.make_key(key, version))

    def add(self, key, value, timeout=None, version=None):
        return self.__cache.add(self.make_key(key, version), value, timeout=None, version=None)

    def delete(self, key, version=None):
        return self.__cache.delete(self.make_key(key, version))

    def clear(self):
        pass

    def close(self, **kwargs):
        self.disconnect_all()<commit_msg>修正使用sae的kvdb作为缓存出错问题<commit_after># coding:UTF-8


"""
缓存模块
@author:yubang
"""


from django.core.cache.backends.base import BaseCache
import sae.kvdb


class SaeKVCache(BaseCache):
    """基于sae的django缓存模块"""
    def __init__(self, server, param):
        self.timeout = param.get('timeout', 1800)
        self.key_prefix = param.get('key_prefix', 'windPlug')
        self.__cache = sae.kvdb.Client()

    def __del__(self):
        pass

    def make_key(self, key, version=None):
        if version is None:
            version = 'default'
        else:
            version = str(version)
        return str('_'.join((self.key_prefix, version, key)))

    def has_key(self, key, version=None):
        return self.__cache.get(self.make_key(key, version)) is not None

    def set(self, key, value, timeout=None, version=None):
        return self.__cache.set(self.make_key(key, version), value)

    def get(self, key, default=None, version=None):
        return self.__cache.get(self.make_key(key, version))

    def add(self, key, value, timeout=None, version=None):
        return self.__cache.add(self.make_key(key, version), value, timeout=None, version=None)

    def delete(self, key, version=None):
        return self.__cache.delete(self.make_key(key, version))

    def clear(self):
        pass

    def close(self, **kwargs):
        self.disconnect_all()
{'fraction_non_alphanumeric': 0.13099824868651488, 'fraction_numerical': 0.0035026269702276708, 'mean_word_length': 3.051063829787234, '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': '2951623', 'n_tokens_mistral': 950, 'n_tokens_neox': 926, 'n_words': 206}