|
| | cachedir = cachedir.rstrip('/') if os.path.exists(cachedir) else None |
| | form = form |
Definition at line 11 of file AtlRunQueryCache.py.
◆ __init__()
| python.utils.AtlRunQueryCache.Cache.__init__ |
( |
| self, |
|
|
| cachedir, |
|
|
| form ) |
Definition at line 12 of file AtlRunQueryCache.py.
12 def __init__(self,cachedir,form):
13 self._cache = {}
14 self.cachedir = cachedir.rstrip('/') if os.path.exists(cachedir) else None
15 self.form = form
16 if self.cachedir:
17 print ("Initializing the cache at",cachedir.rstrip('/'))
18
19
◆ __call__()
| python.utils.AtlRunQueryCache.Cache.__call__ |
( |
| self, |
|
|
| f, |
|
|
* | args, |
|
|
** | kwds ) |
Definition at line 20 of file AtlRunQueryCache.py.
20 def __call__(self, f, *args, **kwds):
21 if not self.cachedir:
22 return f
23
24 print ("Providing cache functionality for function '%s()'" % f.func_name)
25 def newf(*args, **kwds):
26 key = kwds['cachekey']
27 if not self.__is_cached(key):
28 self.__write_to_cache(key,f(*args, **kwds))
29 else:
30 if DEBUG:
31 print ("DEBUG: returning cached value for '%s'" % (self.form % key))
32 pass
33 return self._cache[key]
34 return newf
35
◆ __is_cached()
| python.utils.AtlRunQueryCache.Cache.__is_cached |
( |
| self, |
|
|
| key ) |
|
private |
Definition at line 55 of file AtlRunQueryCache.py.
55 def __is_cached(self,key):
56
57 if key in self._cache:
58 return True
59
60
61 pfname = self.__name_pickle_cache(key)
62 try:
63 pf = open( pfname, 'r' )
64 except OSError:
65 if DEBUG:
66 print ('DEBUG: could not read from cache: ' + pfname)
67 return False
68 try:
69 self._cache[key] = pickle.load(pf)
70 except pickle.UnpicklingError as err:
71 print ("ERROR: could not unpickle %s (%s)" % (pfname, err))
72 sys.exit(1)
73 pf.close()
74 return True
75
76
77
78
79
◆ __name_pickle_cache()
| python.utils.AtlRunQueryCache.Cache.__name_pickle_cache |
( |
| self, |
|
|
| key ) |
|
private |
Definition at line 36 of file AtlRunQueryCache.py.
36 def __name_pickle_cache(self,key):
37 filename = self.form % key
38 return '%s/%s.pickle' % (self.cachedir, filename)
39
40
◆ __write_to_cache()
| python.utils.AtlRunQueryCache.Cache.__write_to_cache |
( |
| self, |
|
|
| key, |
|
|
| value ) |
|
private |
Definition at line 41 of file AtlRunQueryCache.py.
41 def __write_to_cache(self,key, value):
42
43 self._cache[key] = value
44
45
46 pfname = self.__name_pickle_cache(key)
47 pf = open( pfname, 'w' )
48 try:
49 pickle.dump(value, pf)
50 except pickle.PicklingError as err:
51 print ('ERROR: could not write to cache: %s (%s)' % (pfname, err))
52 sys.exit(1)
53 pf.close()
54
◆ _cache
| dict python.utils.AtlRunQueryCache.Cache._cache = {} |
|
protected |
◆ cachedir
| python.utils.AtlRunQueryCache.Cache.cachedir = cachedir.rstrip('/') if os.path.exists(cachedir) else None |
◆ form
| python.utils.AtlRunQueryCache.Cache.form = form |
The documentation for this class was generated from the following file: