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
...@@ -53,6 +53,11 @@ class DistributedRamCache(BaseCache): ...@@ -53,6 +53,11 @@ class DistributedRamCache(BaseCache):
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
## "MemCached: while expecting 'STORED', got unexpected response 'END'" ## "MemCached: while expecting 'STORED', got unexpected response 'END'"
......
...@@ -43,6 +43,11 @@ class RamCache(BaseCache): ...@@ -43,6 +43,11 @@ 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
......
...@@ -106,6 +106,8 @@ class SQLCache(BaseCache): ...@@ -106,6 +106,8 @@ class SQLCache(BaseCache):
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
...@@ -118,6 +120,18 @@ class SQLCache(BaseCache): ...@@ -118,6 +120,18 @@ 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.
...@@ -140,7 +154,6 @@ class SQLCache(BaseCache): ...@@ -140,7 +154,6 @@ class SQLCache(BaseCache):
## 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)
cursor = self.execSQLQuery(sql_query) cursor = self.execSQLQuery(sql_query)
......
...@@ -160,7 +160,6 @@ class CacheTool(BaseTool): ...@@ -160,7 +160,6 @@ 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
...@@ -168,6 +167,9 @@ class CacheTool(BaseTool): ...@@ -168,6 +167,9 @@ class CacheTool(BaseTool):
## 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