'Periodically remove any stale queries in our cache.'

def prune(self):

    last = 0
    while 1:
        if (time.time() < (last + self.threshold_prune)):
            time.sleep(0.2)
            continue
        self.locks.checkout.acquire()
        try:
            for (key, entry) in tuple(self.cache.items()):
                available = entry.lock.acquire(False)
                if (not available):
                    continue
                try:
                    if ((time.time() - entry.timestamp) > self.threshold_prune):
                        del self.cache[key]
                finally:
                    entry.lock.release()
        finally:
            self.locks.checkout.release()
        last = time.time()
