'saves the cache entry specified to disk
:param key:
the entry to flush to disk; if None, all entries in the cache will
be written to disk'

def save(self, key=None):

    if (not self._dirty):
        return
    with self._disk_lock:
        with self._write_lock:
            _objs = copy.deepcopy(self._objects)
            self._dirty = False
        if (key is None):
            delete_keys = [k for k in _objs if (_objs[k] is _invalid_object)]
            for k in delete_keys:
                del _objs[k]
            if _objs:
                make_dirs(self.cache_path)
                for k in _objs.keys():
                    try:
                        self._write(k, _objs)
                    except:
                        traceback.print_exc()
            else:
                try:
                    shutil.rmtree(self.cache_path)
                except:
                    print 'error    while    deleting    {0}'.format(self.cache_path)
                    traceback.print_exc()
        elif (key in _objs):
            if (_objs[key] is _invalid_object):
                file_path = os.path.join(self.cache_path, key)
                try:
                    os.path.remove(file_path)
                except:
                    print 'error    while    deleting    {0}'.format(file_path)
                    traceback.print_exc()
            else:
                make_dirs(self.cache_path)
                self._write(key, _objs)
