-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathcache.py
58 lines (42 loc) · 1.08 KB
/
cache.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# !/usr/bin/python3
# -*- coding: utf-8 -*-
# @Author: 花菜
# @File: cache.py
# @Time : 2023/5/12 17:56
# @Email: [email protected]
from abc import ABC, abstractmethod
class Cache:
def __init__(self):
...
@abstractmethod
def get(self, key: str):
...
@abstractmethod
def set(self, key, value, ttl: int = -1):
...
@abstractmethod
def get_all_pid(self):
pass
@abstractmethod
def get_all_tasks(self) -> dict:
...
@abstractmethod
def remove(self, key):
pass
class DictCache(Cache, ABC):
def __init__(self):
super().__init__()
self._cache = {}
def get(self, key: str):
return self._cache.get(key)
def set(self, key, value, ttl: int = -1):
self._cache[key] = value
def get_all_pid(self) -> list[int]:
return list(self._cache.values())
def get_all_tasks(self) -> dict:
return self._cache
def remove(self, key: str) -> bool:
if key in self._cache:
del self._cache[key]
return True
return False