'Flush the cache.
If I{key} is specified, only that item is flushed.  Otherwise
the entire cache is flushed.
@param key: the key to flush
@type key: (dns.name.Name, int, int) tuple or None'

def flush(self, key=None):

    try:
        self.lock.acquire()
        if (key is not None):
            node = self.data.get(key)
            if (node is not None):
                node.unlink()
                del self.data[node.key]
        else:
            node = self.sentinel.next
            while (node != self.sentinel):
                next = node.next
                node.prev = None
                node.next = None
                node = next
            self.data = {}
    finally:
        self.lock.release()
