1 import threading, weakref
4 __slots__ = ["p", "n", "id", "obj", "st", "lk"]
5 def __init__(self, id, c):
22 if self.n is not None:
33 if self.n is not None:
35 if self.p is not None:
44 def __init__(self, *, keep=1000):
47 self.mru = self.lru = None
49 self.lk = threading.Lock()
53 for i in range(self.n - n):
55 ent.obj = weakref.ref(ent.obj)
57 elif ent.st == "w" and ent.obj() is None:
63 def get(self, id, load=True):
66 ent = self.cur.get(id)
70 self.cur[id] = ent = entry(id, self)
71 ent.lk = lk = threading.Lock()
96 ret = ent.obj = self.load(id)
110 def put(self, id, ob):
113 ent = self.cur.get(id)
115 self.cur[id] = ent = entry(id, self)
118 self._trim(self.keep)
135 def remove(self, id):
138 ent = self.cur.get(id)