File size: 603 Bytes
7d23b62
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from cachetools import LRUCache
from .config import config

class Cache:
    def __init__(self, capacity=1000000):
        self.capacity = capacity
        self.cache = LRUCache(maxsize=capacity)
        self.enable_cache = config['enableCache']

    def get(self, key):
        if not self.enable_cache:
            return None
        return self.cache.get(key, None)

    def put(self, key, value):
        if not self.enable_cache:
            return
        self.cache[key] = value

    def has(self, key):
        if not self.enable_cache:
            return False
        return key in self.cache