<commit_before>from time import time


class Algorith(object):
    LRU = 1
    # TODO MRU = 2
    # TODO RR  = 3
    # TODO LFU = 4


class EasyCache(object):

    def __init__(self, capacity=100, timeout=180, algorith=Algorith.LRU):
        self.capacity = capacity
        self.timeout = 180
        self.algorith = algorith
        self._cache = {}

    def remove(self, key):
        if key in self._cache:
            self._cache = dict(self._cache)
            del self._cache[key]

    def _purgue(self):
        if len(self._cache) > self.capacity:
            num_items_to_remove = len(self._cache) - self.capacity

            if self.algorith == Algorith.LRU:
                sorted_cache = sorted(self._cache.items(), key=lambda x: x[1][3])

                for item in range(0 , num_items_to_remove - 1):
                    self.remove(sorted_cache.items()[0][0])

    def get(self, key):
        try:
            eviction, value, hits, used = self._cache[key]

            if eviction < time():
                self.remove(key)
                return None
            else:
                return value
        except KeyError:
            return None

    def set(self, key, value, timeout=None):
        timeout = self.timeout if not timeout else timeout
        try:
            if key in self._cache:
                _eviction, _value, _hits, _used = self._cache[key]
                self._cache[key] = (_eviction, value, _hits + 1, time())
            else:
                self._cache[key] = (time() + timeout, value, 0, time() + timeout)
                self._purgue()
            return True
        except:
            return False
<commit_msg>Removed hardcoded timeout<commit_after>from time import time


class Algorith(object):
    LRU = 1
    # TODO MRU = 2
    # TODO RR  = 3
    # TODO LFU = 4


class EasyCache(object):

    def __init__(self, capacity=100, timeout=180, algorith=Algorith.LRU):
        self.capacity = capacity
        self.timeout = timeout
        self.algorith = algorith
        self._cache = {}

    def remove(self, key):
        if key in self._cache:
            self._cache = dict(self._cache)
            del self._cache[key]

    def _purgue(self):
        if len(self._cache) > self.capacity:
            num_items_to_remove = len(self._cache) - self.capacity

            if self.algorith == Algorith.LRU:
                sorted_cache = sorted(self._cache.items(), key=lambda x: x[1][3])

                for item in range(0 , num_items_to_remove - 1):
                    self.remove(sorted_cache.items()[0][0])

    def get(self, key):
        try:
            eviction, value, hits, used = self._cache[key]

            if eviction < time():
                self.remove(key)
                return None
            else:
                return value
        except KeyError:
            return None

    def set(self, key, value, timeout=None):
        timeout = self.timeout if not timeout else timeout
        try:
            if key in self._cache:
                _eviction, _value, _hits, _used = self._cache[key]
                self._cache[key] = (_eviction, value, _hits + 1, time())
            else:
                self._cache[key] = (time() + timeout, value, 0, time() + timeout)
                self._purgue()
            return True
        except:
            return False

{'fraction_non_alphanumeric': 0.10202863961813842, 'fraction_numerical': 0.011634844868735084, 'mean_word_length': 1.6464088397790055, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '7513020', 'n_tokens_mistral': 1027, 'n_tokens_neox': 948, 'n_words': 260}