'Drop indeces and tree from cache that have not been
accessed in over 5 minutes.
To attempt to keep memory consumption under control we want to
ensure we don\'t keep everything cached from the db in memory
until process completion. The plan is to have a thread
periodically cull memory.'

def cull_mem(self):

    log.debug('LangZone:    culling    memory')
    TIME_SINCE_ACCESS = 300.0
    self._acquire_lock()
    try:
        N = 30
        if (len(self._index_and_atime_from_dbsubpath) < N):
            return
        now = time.time()
        for (dbsubpath, (index, atime)) in self._index_and_atime_from_dbsubpath.items():
            if ((now - atime) > TIME_SINCE_ACCESS):
                if (dbsubpath in self._is_index_dirty_from_dbsubpath):
                    self.save_index(dbsubpath, index)
                    del self._is_index_dirty_from_dbsubpath[dbsubpath]
                del self._index_and_atime_from_dbsubpath[dbsubpath]
    except:
        log.exception('Exception    culling    memory')
    finally:
        self._release_lock()
