|
ATLAS Offline Software
|
Go to the documentation of this file.
5 from __future__
import print_function
15 self.
cachedir = cachedir.rstrip(
'/')
if os.path.exists(cachedir)
else None
18 print (
"Initializing the cache at",cachedir.rstrip(
'/'))
25 print (
"Providing cache functionality for function '%s()'" % f.func_name)
26 def newf(*args, **kwds):
27 key = kwds[
'cachekey']
32 print (
"DEBUG: returning cached value for '%s'" % (self.
form % key))
38 filename = self.
form % key
39 return '%s/%s.pickle' % (self.
cachedir, filename)
48 pf =
open( pfname,
'w' )
50 pickle.dump(value, pf)
51 except pickle.PicklingError
as err:
52 print (
'ERROR: could not write to cache: %s (%s)' % (pfname, err))
64 pf =
open( pfname,
'r' )
67 print (
'DEBUG: could not read from cache: ' + pfname)
70 self.
_cache[key] = pickle.load(pf)
71 except pickle.UnpicklingError
as err:
72 print (
"ERROR: could not unpickle %s (%s)" % (pfname, err))
81 if __name__ ==
"__main__":
82 @
Cache(
"/afs/cern.ch/user/s/stelzer/runsummary/cache/",
"simple_%i_second%i")
def __write_to_cache(self, key, value)
def __call__(self, f, *args, **kwds)
def aFunction(x, y, cachekey)
def __is_cached(self, key)
def __name_pickle_cache(self, key)
def __init__(self, cachedir, form)