Commit 856652e6 authored by Yoshinori Okuji's avatar Yoshinori Okuji

Use CachingMethod instead of yet another caching system.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@857 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 52cd1341
...@@ -17,7 +17,6 @@ $Id$ ...@@ -17,7 +17,6 @@ $Id$
import Globals import Globals
from Globals import package_home from Globals import package_home
from time import time
#from Products.ERP5 import content_classes #from Products.ERP5 import content_classes
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from Products.CMFDefault.Portal import CMFSite, PortalGenerator from Products.CMFDefault.Portal import CMFSite, PortalGenerator
...@@ -27,8 +26,7 @@ from Products.ERP5Type.Document.Folder import FolderMixIn ...@@ -27,8 +26,7 @@ from Products.ERP5Type.Document.Folder import FolderMixIn
from Products.ERP5Type.Document import addFolder from Products.ERP5Type.Document import addFolder
from Acquisition import aq_base, aq_parent, aq_inner, aq_acquire from Acquisition import aq_base, aq_parent, aq_inner, aq_acquire
import ERP5Globals import ERP5Globals
from Products.ERP5Type.Cache import CachingMethod
import threading
from zLOG import LOG from zLOG import LOG
...@@ -38,11 +36,6 @@ import os ...@@ -38,11 +36,6 @@ import os
#for c in content_classes: #for c in content_classes:
# factory_type_information.append(getattr(c, 'factory_type_information', [])) # factory_type_information.append(getattr(c, 'factory_type_information', []))
# Optimized Module Menu
GLOBAL_MODULE_CACHE_DURATION = 300
cached_modules = {}
cached_modules_time = {}
# Site Creation DTML # Site Creation DTML
manage_addERP5SiteForm = Globals.HTMLFile('dtml/addERP5Site', globals()) manage_addERP5SiteForm = Globals.HTMLFile('dtml/addERP5Site', globals())
manage_addERP5SiteForm.__name__ = 'addERP5Site' manage_addERP5SiteForm.__name__ = 'addERP5Site'
...@@ -174,18 +167,21 @@ class ERP5Site ( CMFSite, FolderMixIn ): ...@@ -174,18 +167,21 @@ class ERP5Site ( CMFSite, FolderMixIn ):
Return a list of modules - result dependent on user - result is translated and cached Return a list of modules - result dependent on user - result is translated and cached
""" """
# Return Cache # Return Cache
def getModuleListFor(user):
result = []
for module in self.objectValues('ERP5 Folder'):
# XXX Restrict access to modules to valid users
result.append({'url': module.absolute_url(), 'id': module.getId(), 'title': self.gettext(module.getTitle())})
result.sort(lambda x,y: cmp(x['title'], y['title']))
return result
user = str(_getAuthenticatedUser(self)) user = str(_getAuthenticatedUser(self))
if cached_modules.has_key(user): method = CachingMethod(getModuleListFor, id='getModuleList', cache_duration=300)
if time() - cached_modules_time[user] < GLOBAL_MODULE_CACHE_DURATION: return method(user)
return cached_modules[user]
result = [] #getModuleList = CachingMethod(getModuleList, cache_duration=300, request_keys=('AUTHENTICATED_USER', 'time'))
for module in self.objectValues('ERP5 Folder'):
# XXX Restrict access to modules to valid users
result.append({'url': module.absolute_url(), 'id': module.getId(), 'title': self.gettext(module.getTitle())})
result.sort(lambda x,y: cmp(x['title'], y['title']))
cached_modules[user] = result
cached_modules_time[user] = time()
return cached_modules[user]
security.declarePublic('getOrderedGlobalActionList') security.declarePublic('getOrderedGlobalActionList')
def getOrderedGlobalActionList(self, action_list): def getOrderedGlobalActionList(self, action_list):
......
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