コード例 #1
0
ファイル: diskCache.py プロジェクト: smulloni/satimol
 def _store(self, entry, canonicalName, cacheKey):
     entry.stored=time.time()
     p=self._path_for_name_and_key(canonicalName, cacheKey)
     debug("cache path is %r", p)
     dname=dirname(p)
     try:
         os.makedirs(dname)
     except OSError, e:
         if e.errno!=errno.EEXIST:
             if self.safe:
                 exception("error trying to create directory %s", dname)
             else:
                 raise
コード例 #2
0
ファイル: diskCache.py プロジェクト: smulloni/satimol
 def _retrieve(self, canonicalName, cacheKey):
     p=self._path_for_name_and_key(canonicalName, cacheKey)
     try:
         f=file(p)
     except IOError, e:
         if e.errno==errno.ENOENT:
             # not in cache
             return None
         else:
             # some other problem
             if self.safe:
                 exception("error trying to retrieve name %s, key %s, but soldiering on",
                           canonicalName,
                           cacheKey)
                 return None
             else:
                 raise
コード例 #3
0
ファイル: diskCache.py プロジェクト: smulloni/satimol
         if e.errno!=errno.EEXIST:
             if self.safe:
                 exception("error trying to create directory %s", dname)
             else:
                 raise
     try:
         fd, tempname=tempfile.mkstemp(suffix=".tmp",
                                       dir=dname)
         tempf=os.fdopen(fd, 'w')
         cPickle.dump(entry, tempf)
         tempf.close()
         os.rename(tempname, p)
     except:
         if self.safe:
             exception("error trying to store name %s, key %s, but soldiering on",
                       canonicalName,
                       cackeKey)
         else:
             raise
     
 def invalidate(self, canonicalName):
     """
     removes cache entries for the canonicalName.
     This does not actually delete the cache entries, but
     renames them. 
     """
     p=self._path_for_name(canonicalName)
     dname=dirname(p)
     # we need a name that isn't in use;
     # the same canonicalName may be invalidated
     # multiple times between cache clears.