Commit 09e7dfa6 authored by Ivan Tyagov's avatar Ivan Tyagov

Added initCacheStorage method which will init (if needed) cache backend...

Added initCacheStorage method which will init (if needed) cache backend storage when cache is updated

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@11204 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 77be74eb
......@@ -52,6 +52,11 @@ class DistributedRamCache(BaseCache):
self._debugLevel = params.get('debugLevel', 7)
self._last_cache_conn_creation_time = time()
BaseCache.__init__(self)
def initCacheStorage(self):
""" Init cache storage """
## cache storage is a memcached server and no need to init it
pass
def getCacheStorage(self):
## if we use one connection object this causes
......
......@@ -42,7 +42,12 @@ class RamCache(BaseCache):
def __init__(self, params={}):
BaseCache.__init__(self)
def initCacheStorage(self):
""" Init cache storage """
## cache storage is a RAM based dictionary
pass
def getCacheStorage(self):
return self._cache_dict
......
......@@ -105,7 +105,9 @@ class SQLCache(BaseCache):
FROM %s
WHERE scope="%s"
'''
find_table_by_name_sql = """SHOW TABLES LIKE '%s' """
def __init__(self, params):
BaseCache.__init__(self)
self._dbConn = None
......@@ -117,7 +119,19 @@ class SQLCache(BaseCache):
## since SQL cache is persistent check for expired objects
#self.expireOldCacheEntries(forceCheck=True)
def initCacheStorage(self):
""" Init cache backedn storage by creating needed cache table in RDBMS """
sql_query = self.find_table_by_name_sql %self._db_cache_table_name
cursor = self.execSQLQuery(sql_query)
result = cursor.fetchall()
if 0 < len(result):
## we have such table
pass
else:
## no such table create it
self.execSQLQuery(self.create_table_sql %self._db_cache_table_name)
def getCacheStorage(self):
"""
Return current DB connection or create a new one for this thread.
......@@ -139,7 +153,6 @@ class SQLCache(BaseCache):
else:
## we have already dbConn for this thread
return dbConn
def get(self, cache_id, scope, default=None):
sql_query = self.get_key_sql %(self._db_cache_table_name, cache_id, scope)
......
......@@ -160,14 +160,16 @@ class CacheTool(BaseTool):
security.declareProtected(Permissions.ModifyPortalContent, 'updateCache')
def updateCache(self, REQUEST=None):
""" Clear and update cache structure """
#erp5_site_id = self.getPortalObject().getId()
for cf in CachingMethod.factories:
for cp in CachingMethod.factories[cf].getCachePluginList():
for cp in CachingMethod.factories[cf].getCachePluginList():
del cp
CachingMethod.factories = {}
## read configuration from ZODB
for key,item in self.getCacheFactoryList().items():
if len(item['cache_plugins'])!=0:
## init cache backend storages
for cp in item["cache_plugins"]:
cp.initCacheStorage()
CachingMethod.factories[key] = CacheFactory(item['cache_plugins'], item['cache_params'])
if REQUEST is not None:
self.REQUEST.RESPONSE.redirect('cache_tool_configure?portal_status_message=Cache updated.')
......
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