[Zope-Checkins] CVS: Zope/lib/python/App - CacheManager.py:1.29
Fred Drake
cvs-admin at zope.org
Mon Nov 3 14:08:45 EST 2003
Update of /cvs-repository/Zope/lib/python/App
In directory cvs.zope.org:/tmp/cvs-serv12969
Modified Files:
CacheManager.py
Log Message:
lots of cleanup; remove archaic BoboPOS 2 support
=== Zope/lib/python/App/CacheManager.py 1.28 => 1.29 ===
--- Zope/lib/python/App/CacheManager.py:1.28 Mon Nov 3 11:40:37 2003
+++ Zope/lib/python/App/CacheManager.py Mon Nov 3 14:08:44 2003
@@ -10,104 +10,82 @@
# FOR A PARTICULAR PURPOSE
#
##############################################################################
-__doc__='''Cache management support
+'''Cache management support.
+This class is mixed into the database manager in App.ApplicationManager.
$Id$'''
__version__='$Revision$'[11:-2]
-import Globals, time, sys
+import time
+
+import Globals
from DateTime import DateTime
class CacheManager:
"""Cache management mix-in
"""
- _cache_age=60
- _vcache_age=60
+ _cache_age = 60
+ _vcache_age = 60
_history_length = 3600 # Seconds
- manage_cacheParameters=Globals.DTMLFile('dtml/cacheParameters', globals())
- manage_cacheGC=Globals.DTMLFile('dtml/cacheGC', globals())
+ manage_cacheParameters = Globals.DTMLFile('dtml/cacheParameters',
+ globals())
+ manage_cacheGC = Globals.DTMLFile('dtml/cacheGC', globals())
transparent_bar = Globals.ImageFile('www/transparent_bar.gif', globals())
store_bar = Globals.ImageFile('www/store_bar.gif', globals())
load_bar = Globals.ImageFile('www/load_bar.gif', globals())
+ def _getDB(self):
+ return self._p_jar.db()
+
+ def _inVersion(self):
+ return self._p_jar.getVersion() and True or False
+
def cache_length(self):
- try: db=self._p_jar.db()
- except:
- # BoboPOS2
- return len(Globals.Bobobase._jar.cache)
- else: return db.cacheSize()
+ return self._getDB().cacheSize()
def cache_detail_length(self):
- try: db=self._p_jar.db()
- except:
- return ()
- else: return db.cacheDetailSize()
+ return self._getDB().cacheDetailSize()
def database_size(self):
- try: db=self._p_jar.db()
- except:
- # BoboPOS2
- return len(Globals.Bobobase._jar.db.index)*4
- else: return db.objectCount()
+ return self._getDB().objectCount()
def cache_age(self):
- try:
- if self._p_jar.getVersion():
- return self._vcache_age
- except: pass
-
- return self._cache_age
+ if self._inVersion():
+ return self._vcache_age
+ else:
+ return self._cache_age
def manage_cache_age(self,value,REQUEST):
"set cache age"
- try:
- v=self._p_jar.getVersion()
- except:
- # BoboPOS2:
- if self._p_jar.db is not Globals.Bobobase._jar.db:
- raise 'Version Error', (
- '''You may not change the database cache age
- while working in a <em>version</em>''')
- self._cache_age=Globals.Bobobase._jar.cache.cache_age=value
- else:
- if v:
- self._vcache_age=value
- self._p_jar.db().setVersionCacheDeactivateAfter(value)
- else:
- self._cache_age=value
- self._p_jar.db().setCacheDeactivateAfter(value)
+ db = self._getDB()
+ if self._inVersion():
+ self._vcache_age = value
+ db.setVersionCacheDeactivateAfter(value)
+ else:
+ self._cache_age = value
+ db.setCacheDeactivateAfter(value)
if REQUEST is not None:
response=REQUEST['RESPONSE']
response.redirect(REQUEST['URL1']+'/manage_cacheParameters')
def cache_size(self):
- try:
- if self._p_jar.getVersion():
- return self._p_jar.db().getVersionCacheSize()
- except: pass
- return self._p_jar.db().getCacheSize()
+ db = self._getDB()
+ if self._inVersion():
+ return db.getVersionCacheSize()
+ else:
+ return db.getCacheSize()
def manage_cache_size(self,value,REQUEST):
"set cache size"
- try:
- v=self._p_jar.getVersion()
- except:
- # BoboPOS2:
- if self._p_jar.db is not Globals.Bobobase._jar.db:
- raise 'Version Error', (
- '''You may not change the database cache size
- while working in a <em>version</em>''')
- Globals.Bobobase._jar.cache.cache_size = value
- else:
- db = self._p_jar.db()
- if v:
- db.setVersionCacheSize(value)
- else:
- db.setCacheSize(value)
+ db = self._getDB()
+ if self._inVersion():
+ db.setVersionCacheSize(value)
+ else:
+ db.setCacheSize(value)
if REQUEST is not None:
response=REQUEST['RESPONSE']
@@ -115,24 +93,7 @@
def cacheStatistics(self):
- try: return self._p_jar.db().cacheStatistics()
- except: pass
-
- # BoboPOS 2
- return (
- ('Mean time since last access (minutes)',
- "%.4g" % (Globals.Bobobase._jar.cache.cache_mean_age/60.0)),
- ('Deallocation rate (objects/minute)',
- "%.4g" % (Globals.Bobobase._jar.cache.cache_mean_deal*60)),
- ('Deactivation rate (objects/minute)',
- "%.4g" % (Globals.Bobobase._jar.cache.cache_mean_deac*60)),
- ('Time of last cache garbage collection',
- time.asctime(time.localtime(
- Globals.Bobobase._jar.cache.cache_last_gc_time
- ))
- ),
- )
-
+ return self._getDB().cacheStatistics()
# BoboPOS 2
def cache_mean_age(self):
@@ -153,11 +114,8 @@
def manage_full_sweep(self,value,REQUEST):
"Perform a full sweep through the cache"
- try: db=self._p_jar.db()
- except:
- # BoboPOS2
- Globals.Bobobase._jar.cache.full_sweep(value)
- else: db.cacheFullSweep(value)
+ db = self._getDB()
+ db.cacheFullSweep(value)
if REQUEST is not None:
response=REQUEST['RESPONSE']
@@ -165,11 +123,7 @@
def manage_minimize(self,value=1,REQUEST=None):
"Perform a full sweep through the cache"
- try: db=self._p_jar.db()
- except:
- # BoboPOS2
- Globals.Bobobase._jar.cache.minimize(value)
- else: db.cacheMinimize(value)
+ self._getDB().cacheMinimize(value)
if REQUEST is not None:
response=REQUEST['RESPONSE']
@@ -184,8 +138,7 @@
Returns the name of the classes of the objects in the cache
and the number of objects in the cache for each class.
"""
- db=self._p_jar.db()
- detail = db.cacheDetail()
+ detail = self._getDB().cacheDetail()
if REQUEST is not None:
# format as text
REQUEST.RESPONSE.setHeader('Content-Type', 'text/plain')
@@ -199,8 +152,7 @@
"""
Returns information about each object in the cache.
"""
- db=self._p_jar.db()
- detail = db.cacheExtremeDetail()
+ detail = self._getDB().cacheExtremeDetail()
if REQUEST is not None:
# sort the list.
lst = map(lambda dict: ((dict['conn_no'], dict['oid']), dict),
@@ -233,7 +185,7 @@
return detail
def _getActivityMonitor(self):
- db = self._p_jar.db()
+ db = self._getDB()
if not hasattr(db, 'getActivityMonitor'):
return None
am = db.getActivityMonitor()
More information about the Zope-Checkins
mailing list