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): ...@@ -52,6 +52,11 @@ class DistributedRamCache(BaseCache):
self._debugLevel = params.get('debugLevel', 7) self._debugLevel = params.get('debugLevel', 7)
self._last_cache_conn_creation_time = time() self._last_cache_conn_creation_time = time()
BaseCache.__init__(self) 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): def getCacheStorage(self):
## if we use one connection object this causes ## if we use one connection object this causes
......
...@@ -42,7 +42,12 @@ class RamCache(BaseCache): ...@@ -42,7 +42,12 @@ class RamCache(BaseCache):
def __init__(self, params={}): def __init__(self, params={}):
BaseCache.__init__(self) BaseCache.__init__(self)
def initCacheStorage(self):
""" Init cache storage """
## cache storage is a RAM based dictionary
pass
def getCacheStorage(self): def getCacheStorage(self):
return self._cache_dict return self._cache_dict
......
...@@ -105,7 +105,9 @@ class SQLCache(BaseCache): ...@@ -105,7 +105,9 @@ class SQLCache(BaseCache):
FROM %s FROM %s
WHERE scope="%s" WHERE scope="%s"
''' '''
find_table_by_name_sql = """SHOW TABLES LIKE '%s' """
def __init__(self, params): def __init__(self, params):
BaseCache.__init__(self) BaseCache.__init__(self)
self._dbConn = None self._dbConn = None
...@@ -117,7 +119,19 @@ class SQLCache(BaseCache): ...@@ -117,7 +119,19 @@ class SQLCache(BaseCache):
## since SQL cache is persistent check for expired objects ## since SQL cache is persistent check for expired objects
#self.expireOldCacheEntries(forceCheck=True) #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): def getCacheStorage(self):
""" """
Return current DB connection or create a new one for this thread. Return current DB connection or create a new one for this thread.
...@@ -139,7 +153,6 @@ class SQLCache(BaseCache): ...@@ -139,7 +153,6 @@ class SQLCache(BaseCache):
else: else:
## we have already dbConn for this thread ## we have already dbConn for this thread
return dbConn return dbConn
def get(self, cache_id, scope, default=None): def get(self, cache_id, scope, default=None):
sql_query = self.get_key_sql %(self._db_cache_table_name, cache_id, scope) sql_query = self.get_key_sql %(self._db_cache_table_name, cache_id, scope)
......
...@@ -160,14 +160,16 @@ class CacheTool(BaseTool): ...@@ -160,14 +160,16 @@ class CacheTool(BaseTool):
security.declareProtected(Permissions.ModifyPortalContent, 'updateCache') security.declareProtected(Permissions.ModifyPortalContent, 'updateCache')
def updateCache(self, REQUEST=None): def updateCache(self, REQUEST=None):
""" Clear and update cache structure """ """ Clear and update cache structure """
#erp5_site_id = self.getPortalObject().getId()
for cf in CachingMethod.factories: for cf in CachingMethod.factories:
for cp in CachingMethod.factories[cf].getCachePluginList(): for cp in CachingMethod.factories[cf].getCachePluginList():
del cp del cp
CachingMethod.factories = {} CachingMethod.factories = {}
## read configuration from ZODB ## read configuration from ZODB
for key,item in self.getCacheFactoryList().items(): for key,item in self.getCacheFactoryList().items():
if len(item['cache_plugins'])!=0: 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']) CachingMethod.factories[key] = CacheFactory(item['cache_plugins'], item['cache_params'])
if REQUEST is not None: if REQUEST is not None:
self.REQUEST.RESPONSE.redirect('cache_tool_configure?portal_status_message=Cache updated.') 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