def get(self, key): # get value from cache or from DB and update cache if key in self.data: node = self.data[key] previous = node.previous next = node.next if previous != None: previous.next = next else: self.head = next if next != None: next.previous = previous else: self.tail = previous node.next = None node.previous = None self.appendNode(node) return node.data else: dal = DAL() value = dal.getValue(key) if value != None: self.insertInCache(key, value) return value else: return "Error: key %s not found" % key
def put(self, key, value): # Put key, value pair in cache and DB self.insertInCache(key, value) dal = DAL() dal.update(key, value)
def warmUp(self): # Get data from DB to populate cache dal = DAL() for key, value in dal.getKeyValues(): self.insertInCache(key, cPickle.loads(value))