def set(self, key, value, timeout = None): if self.delete(key): self._cache[key].update(value, timeout or self._defaultTimeOut, getTimes()) return True self.add(key, value, timeout) return True
def set(self, key, value): if self.has_key(key): self.pool[key].update(value, getTimes()) # 从索引队列中删除 self._nodeList.remove(key) # 加入到索引队列末尾 self._nodeList.append(key) return True return False
def add(self, key, value): if self.has_key(key): return False if self.count + 1 <= self.maxSize: cTime = getTimes() self.pool[key] = PoolNode(value, cTime) # 增加到索引队列中 self._nodeList.append(key) self.count += 1 return True else: dKey = self._nodeList[0] self.delete(dKey) self.add(key, value) return True
def isInvaild(self): now = getTimes() if now > self._btime + self._timeout: return False return True
def add(self, key, value, timeout = None): if self._cache.has_key(key): return False self._cache[key] = CacheNode(value, timeout or self._defaultTimeOut, getTimes()) return True