def insert_all(self):
     """ Inserts all remaining documents in the cache regardless of their number. """ 
     for wsid, stack in self.insertion_stacks.items():
         db.bulkinsert(stack, wsid)
     self.insertion_stacks = {}
 def insert(self, document, wsid):
     """ Adds a document to an insertion queue which will be inserted after a certain number of  """
     if not self.insertion_stacks.has_key(wsid):
         self.insertion_stacks[wsid] = [document]
     if settings.DEBUG or len(self.insertion_stacks[wsid]) > settings.MAX_BATCH_ENTRIES:
         db.bulkinsert(self.insertion_stacks[wsid], wsid)
         self.insertion_stacks[wsid] = []