1
2
3
4
5
6
7
8
9
10
11
12
13
14 """PObjectCache
15
16 Persistent object cache that should be placed in a temp_folder
17
18 $Id: PObjectCache.py,v 1.2 2003/04/11 15:50:18 edahl Exp $"""
19
20 __version__ = "$Revision: 1.2 $"[11:-2]
21
22 import time
23
24 from Globals import Persistent
25 from Globals import DTMLFile
26 from AccessControl import ClassSecurityInfo
27
28 from OFS.SimpleItem import SimpleItem
29
31 editCache = DTMLFile('dtml/editCache', globals())
32 manage_options = ({'label':'Cache','action':'editCache'},)
33
34 security = ClassSecurityInfo()
35
36 - def __init__(self, id, timeout=20, clearthresh=20):
41
42
53
54
59
64
65
67 """clean the cache if nessesary"""
68 cleared = 0
69 if self.cache:
70 self.clearcount -= 1
71 if force or self.clearcount < self.clearthresh:
72 for key, value in self.cache.items():
73 if not value.checkTime():
74 cleared = 1
75 del self.cache[key]
76 self.clearcount = self.clearthresh
77 return cleared
78
79
82
83
84 security.declareProtected('View','getCacheTimeout')
86 """return cache timeout"""
87 return self.timeout
88
89
90 security.declareProtected('View','getCacheClearthresh')
92 """return cache clearthresh"""
93 return self.clearthresh
94
95
97
99 self._obj = obj
100 self._timeout = timeout
101 self._time = time.time()
102
104 if self._time + self._timeout < time.time():
105 return 0
106 else:
107 return 1
108
111
113 """Return the time at which this cache object was created"""
114 return self._time
115