Commit e3f2a0a2 authored by Ivan Tyagov's avatar Ivan Tyagov Committed by Julien Muchembled

Allow Cache Factory to contain Cache Bags which on its side can

contain Cache Plugins.
Unify in one function cache factory uid generation.
parent 4d6793f7
...@@ -60,6 +60,16 @@ class CacheFactory(XMLObject): ...@@ -60,6 +60,16 @@ class CacheFactory(XMLObject):
, PropertySheet.CacheFactory , PropertySheet.CacheFactory
) )
def getCacheUid(self):
"""
Get a common Cache Factory / Cache Bag UID in this
case relative to portal_caches.
It's required to use relative url (i.e. mainly ID) due
to CachingMethod legacy.
"""
relative_url = self.getRelativeUrl()
assert relative_url[:14] == 'portal_caches/'
return relative_url[14:]
def getCachePluginList(self): def getCachePluginList(self):
""" get ordered list of installed cache plugins in ZODB """ """ get ordered list of installed cache plugins in ZODB """
...@@ -71,7 +81,7 @@ class CacheFactory(XMLObject): ...@@ -71,7 +81,7 @@ class CacheFactory(XMLObject):
security.declareProtected(Permissions.AccessContentsInformation, 'getRamCacheFactory') security.declareProtected(Permissions.AccessContentsInformation, 'getRamCacheFactory')
def getRamCacheFactory(self): def getRamCacheFactory(self):
""" Return RAM based cache factory """ """ Return RAM based cache factory """
cache_factory_name = self.getId() cache_factory_name = self.getCacheUid()
cache_tool = self.portal_caches cache_tool = self.portal_caches
cache_factory = CachingMethod.factories.get(cache_factory_name) cache_factory = CachingMethod.factories.get(cache_factory_name)
#XXX This conditional statement should be remove as soon as #XXX This conditional statement should be remove as soon as
......
...@@ -66,21 +66,14 @@ class CacheTool(BaseTool): ...@@ -66,21 +66,14 @@ class CacheTool(BaseTool):
security.declareProtected(Permissions.AccessContentsInformation, 'getCacheFactoryList') security.declareProtected(Permissions.AccessContentsInformation, 'getCacheFactoryList')
def getCacheFactoryList(self): def getCacheFactoryList(self):
""" Return available cache factories """ """ Return available cache factories """
rd = {}
for cf in self.objectValues(['ERP5 Cache Factory', 'ERP5 Cache Bag']): def getRamCachePlugin(cp):
cache_scope = cf.getId()
rd[cache_scope] = {}
rd[cache_scope]['cache_plugins'] = []
rd[cache_scope]['cache_params'] = {}
for cp in cf.getCachePluginList():
cache_obj = None
cp_meta_type = cp.meta_type cp_meta_type = cp.meta_type
if cp_meta_type == 'ERP5 Ram Cache': if cp_meta_type == 'ERP5 Ram Cache':
cache_obj = RamCache() return RamCache()
elif cp_meta_type == 'ERP5 Distributed Ram Cache': if cp_meta_type == 'ERP5 Distributed Ram Cache':
## even thougn we have such plugin in ZODB that doens't mean ## even thougn we have such plugin in ZODB that doens't mean
## we have corresponding memcache module installed ## we have corresponding memcache module installed
cache_obj = None
if getattr(cp, 'getSpecialiseValue', None) is not None: if getattr(cp, 'getSpecialiseValue', None) is not None:
memcached_plugin = cp.getSpecialiseValue() memcached_plugin = cp.getSpecialiseValue()
if memcached_plugin is not None: if memcached_plugin is not None:
...@@ -90,14 +83,38 @@ class CacheTool(BaseTool): ...@@ -90,14 +83,38 @@ class CacheTool(BaseTool):
'expiration_time': cf.getCacheDuration(), 'expiration_time': cf.getCacheDuration(),
'server_max_key_length': memcached_plugin.getServerMaxKeyLength(), 'server_max_key_length': memcached_plugin.getServerMaxKeyLength(),
'server_max_value_length': memcached_plugin.getServerMaxValueLength(), 'server_max_value_length': memcached_plugin.getServerMaxValueLength(),
'key_prefix': getattr(self, 'erp5_site_global_id', '') 'key_prefix': getattr(self, 'erp5_site_global_id', '')}
} return DistributedRamCache(init_dict)
cache_obj = DistributedRamCache(init_dict)
rd = {}
for cf in self.objectValues(['ERP5 Cache Factory', 'ERP5 Cache Bag']):
cache_scope = cf.getCacheUid()
rd[cache_scope] = {}
rd[cache_scope]['cache_plugins'] = []
rd[cache_scope]['cache_params'] = {}
for cp in cf.getCachePluginList():
cache_obj = getRamCachePlugin(cp)
if cache_obj is not None:
## set cache expire check interval
cache_obj.cache_expire_check_interval = cp.getCacheExpireCheckInterval()
rd[cache_scope]['cache_plugins'].append(cache_obj)
rd[cache_scope]['cache_params']['cache_duration'] = cf.getCacheDuration()
# support for cache bags which are like Cache Factory
# i.e. provide Cache Plugins
for cache_bag in cf.objectValues('ERP5 Cache Bag'):
cache_scope = cache_bag.getCacheUid()
rd[cache_scope] = {}
rd[cache_scope]['cache_plugins'] = []
rd[cache_scope]['cache_params'] = {}
for cp in cache_bag.getCachePluginList():
cache_obj = getRamCachePlugin(cp)
if cache_obj is not None: if cache_obj is not None:
## set cache expire check interval ## set cache expire check interval
cache_obj.cache_expire_check_interval = cp.getCacheExpireCheckInterval() cache_obj.cache_expire_check_interval = cp.getCacheExpireCheckInterval()
rd[cache_scope]['cache_plugins'].append(cache_obj) rd[cache_scope]['cache_plugins'].append(cache_obj)
rd[cache_scope]['cache_params']['cache_duration'] = cf.getCacheDuration() rd[cache_scope]['cache_params']['cache_duration'] = cf.getCacheDuration()
return rd return rd
## ##
......
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