Commit 537cb142 authored by Fred Drake's avatar Fred Drake

Fix collector issue #1105:

Make the cache manager report correct values for the object cache size.
parent 27067290
......@@ -30,6 +30,9 @@ Zope Changes
Bugs fixed
- Made the control panel properly reflect the cache-size setting
of ZODB's object cache once again.
- ConflictError was swallowed in ObjectManager by
manage_beforeDelete and _delObject. This could break code
expecting to do cleanups before deletion.
......
......@@ -13,8 +13,8 @@
__doc__='''Cache management support
$Id: CacheManager.py,v 1.27 2002/10/09 15:11:25 shane Exp $'''
__version__='$Revision: 1.27 $'[11:-2]
$Id: CacheManager.py,v 1.28 2003/11/03 16:40:37 fdrake Exp $'''
__version__='$Revision: 1.28 $'[11:-2]
import Globals, time, sys
from DateTime import DateTime
......@@ -23,9 +23,7 @@ class CacheManager:
"""Cache management mix-in
"""
_cache_age=60
_cache_size=400
_vcache_age=60
_vcache_size=400
_history_length = 3600 # Seconds
manage_cacheParameters=Globals.DTMLFile('dtml/cacheParameters', globals())
......@@ -86,14 +84,12 @@ class CacheManager:
response=REQUEST['RESPONSE']
response.redirect(REQUEST['URL1']+'/manage_cacheParameters')
def cache_size(self):
try:
if self._p_jar.getVersion():
return self._vcache_size
return self._p_jar.db().getVersionCacheSize()
except: pass
return self._cache_size
return self._p_jar.db().getCacheSize()
def manage_cache_size(self,value,REQUEST):
"set cache size"
......@@ -105,14 +101,13 @@ class CacheManager:
raise 'Version Error', (
'''You may not change the database cache size
while working in a <em>version</em>''')
self._cache_size=Globals.Bobobase._jar.cache.cache_size=value
Globals.Bobobase._jar.cache.cache_size = value
else:
db = self._p_jar.db()
if v:
self._vcache_size=value
self._p_jar.db().setVersionCacheSize(value)
db.setVersionCacheSize(value)
else:
self._cache_size=value
self._p_jar.db().setCacheSize(value)
db.setCacheSize(value)
if REQUEST is not None:
response=REQUEST['RESPONSE']
......@@ -181,19 +176,8 @@ class CacheManager:
response.redirect(REQUEST['URL1']+'/manage_cacheGC')
def initialize_cache(self):
try: db=self._p_jar.db()
except:
# BoboPOS2
Globals.Bobobase._jar.cache.cache_size=self._cache_size
Globals.Bobobase._jar.cache.cache_age =self._cache_age
else:
db.setCacheSize(self._cache_size)
db.setCacheDeactivateAfter(self._cache_age)
db.setVersionCacheSize(self._vcache_size)
db.setVersionCacheDeactivateAfter(self._vcache_age)
am = self._getActivityMonitor()
if am is not None:
am.setHistoryLength(self._history_length)
# Cache is always initialized from the configuration file.
pass
def cache_detail(self, REQUEST=None):
"""
......
##############################################################################
#
# Copyright (c) 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Tests for the CacheManager.
$Id: test_cachemanager.py,v 1.1 2003/11/03 16:40:37 fdrake Exp $
"""
import unittest
import ZODB
from App.CacheManager import CacheManager
class TestCacheManager(CacheManager):
# Derived CacheManager that fakes enough of the DatabaseManager to
# make it possible to test at least some parts of the CacheManager.
def __init__(self, connection):
self._p_jar = connection
class DummyConnection:
def __init__(self, db, version=None):
self.__db = db
self.__version = version
def db(self):
return self.__db
def getVersion(self):
return self.__version
class DummyDB:
def __init__(self, cache_size, vcache_size):
self._set_sizes(cache_size, vcache_size)
def _set_sizes(self, cache_size, vcache_size):
self.__cache_size = cache_size
self.__vcache_size = vcache_size
def getCacheSize(self):
return self.__cache_size
def getVersionCacheSize(self):
return self.__vcache_size
class CacheManagerTestCase(unittest.TestCase):
def setUp(self):
self.db = DummyDB(42, 24)
self.connection = DummyConnection(self.db)
self.manager = TestCacheManager(self.connection)
def test_cache_size(self):
self.assertEqual(self.manager.cache_size(), 42)
self.db._set_sizes(12, 2)
self.assertEqual(self.manager.cache_size(), 12)
def test_version_cache_size(self):
self.connection = DummyConnection(self.db, "my version")
self.manager = TestCacheManager(self.connection)
# perform test
self.assertEqual(self.manager.cache_size(), 24)
self.db._set_sizes(12, 2)
self.assertEqual(self.manager.cache_size(), 2)
def test_suite():
return unittest.makeSuite(CacheManagerTestCase)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment