pbf.controller.Cache

 1cacheList: dict = {}
 2
 3
 4def set(key: str, value):
 5    """
 6    Set or replace the key.
 7    :param key: str key
 8    :param value: object value
 9    :return: None
10    """
11    cacheList[key] = value
12
13
14def get(key: str, default=None):
15    """
16    Get the key value.
17    :param key: str key
18    :param default: object (可选)default value
19    :return: value
20    """
21    return cacheList.get(key, default)
22
23
24def delete(key: str):
25    """
26    Delete the key.
27    :param key: str key
28    :return: object value
29    """
30    value = cacheList.get(key)
31    cacheList.pop(key)
32    return value
33
34
35def check(key: str):
36    """
37    Check if the key exists.
38    :param key: str key
39    :return: bool
40    """
41    return key in cacheList
42
43
44if __name__ == '__main__':
45    set('test', 'test')
46    print(get('test'))
47    print(delete('test'))
cacheList: dict = {}
def set(key: str, value):
 5def set(key: str, value):
 6    """
 7    Set or replace the key.
 8    :param key: str key
 9    :param value: object value
10    :return: None
11    """
12    cacheList[key] = value

Set or replace the key.

Parameters
  • key: str key
  • value: object value
Returns

None

def get(key: str, default=None):
15def get(key: str, default=None):
16    """
17    Get the key value.
18    :param key: str key
19    :param default: object (可选)default value
20    :return: value
21    """
22    return cacheList.get(key, default)

Get the key value.

Parameters
  • key: str key
  • default: object (可选)default value
Returns

value

def delete(key: str):
25def delete(key: str):
26    """
27    Delete the key.
28    :param key: str key
29    :return: object value
30    """
31    value = cacheList.get(key)
32    cacheList.pop(key)
33    return value

Delete the key.

Parameters
  • key: str key
Returns

object value

def check(key: str):
36def check(key: str):
37    """
38    Check if the key exists.
39    :param key: str key
40    :return: bool
41    """
42    return key in cacheList

Check if the key exists.

Parameters
  • key: str key
Returns

bool