예제 #1
0
 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  
예제 #2
0
 def put(self, key, value):
     # Put key, value pair in cache and DB
     self.insertInCache(key, value)
     dal = DAL()
     dal.update(key, value)
예제 #3
0
 def warmUp(self):
     # Get data from DB to populate cache
     dal = DAL()
     for key, value in dal.getKeyValues():
         self.insertInCache(key, cPickle.loads(value))