'Decreases the size of the cache by removing n nodes from the tail of the list'

def shrink(self, n):

    n = max(0, min(n, (self._size - 1)))
    left = n
    while (left > 0):
        left -= 1
        node = self.head.prev
        if (not node.empty):
            if (self.callback is not None):
                self.callback(node.key, node.value)
            del self.table[node.key]
        self.head.prev = node.prev
        node.prev.next = self.head
        node.prev = None
        node.next = None
        node.key = None
        node.value = None
    self._size -= n
