-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from IMIO/MOD-910_centralize_caching_mechanism
Mod 910 centralize caching mechanism
- Loading branch information
Showing
26 changed files
with
713 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,6 +48,7 @@ | |
'plone.dexterity', | ||
'setuptools', | ||
'Plone', | ||
'z3c.unconfigure', | ||
], | ||
extras_require={ | ||
'test': [ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,90 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from imio.helpers.cache import get_cachekey_volatile | ||
from plone import api | ||
from plone.memoize import ram as pmram | ||
from Products.PlonePAS.plugins.role import GroupAwareRoleManager | ||
from Products.PlonePAS.tools.groups import GroupsTool | ||
from Products.PluggableAuthService.PluggableAuthService import PluggableAuthService | ||
from zope.globalrequest import getRequest | ||
from zope.i18nmessageid import MessageFactory | ||
|
||
import logging | ||
import os | ||
|
||
|
||
_ = MessageFactory('imio.helpers') | ||
logger = logging.getLogger('imio.helpers') | ||
|
||
|
||
def GroupsTool__getGroupsForPrincipal_cachekey(method, self, principal): | ||
req = getRequest() | ||
if req is None: | ||
raise pmram.DontCache | ||
date = get_cachekey_volatile('_users_groups_value') | ||
return date, principal and principal.getId() | ||
|
||
|
||
def GroupAwareRoleManager__getRolesForPrincipal_cachekey(method, self, principal, request=None): | ||
req = request or getRequest() | ||
# if req is None: | ||
# raise pmram.DontCache | ||
date = get_cachekey_volatile('_users_groups_value') | ||
return (date, principal and principal.getId(), repr(req), req and (req.get('__ignore_direct_roles__', False), | ||
req.get('__ignore_group_roles__', False)) or (None, None)) | ||
|
||
|
||
def PluggableAuthService__getGroupsForPrincipal_cachekey(method, self, principal, request=None, **kwargs): | ||
req = request or getRequest() | ||
if req is None: | ||
raise pmram.DontCache | ||
try: | ||
date = get_cachekey_volatile('_users_groups_value') | ||
except api.portal.CannotGetPortalError: | ||
raise pmram.DontCache | ||
return date, principal and principal.getId() | ||
|
||
|
||
def PluggableAuthService__findUser_cachekey(method, self, plugins, user_id, name=None, request=None): | ||
req = request or getRequest() | ||
if req is None: | ||
raise pmram.DontCache | ||
try: | ||
date = get_cachekey_volatile('_users_groups_value') | ||
except api.portal.CannotGetPortalError: | ||
raise pmram.DontCache | ||
return date, repr(plugins), user_id, name, str(req and req._debug or '') | ||
|
||
|
||
def PluggableAuthService__verifyUser_cachekey(method, self, plugins, user_id=None, login=None): | ||
req = getRequest() | ||
if req is None: | ||
raise pmram.DontCache | ||
|
||
date = get_cachekey_volatile('_users_groups_value') | ||
return date, repr(plugins), user_id, login | ||
|
||
|
||
def GroupsTool_getGroupById_cachekey(method, self, group_id): | ||
req = getRequest() | ||
if req is None: | ||
raise pmram.DontCache | ||
|
||
date = get_cachekey_volatile('_users_groups_value') | ||
return date, group_id | ||
|
||
|
||
if os.getenv('decorate_acl_methods', 'Nope') in ('True', 'true'): | ||
logger.info('DECORATING various acl related methods with cache') | ||
decorator = pmram.cache(GroupsTool__getGroupsForPrincipal_cachekey) | ||
GroupsTool.getGroupsForPrincipal = decorator(GroupsTool.getGroupsForPrincipal) | ||
decorator = pmram.cache(GroupAwareRoleManager__getRolesForPrincipal_cachekey) | ||
GroupAwareRoleManager.getRolesForPrincipal = decorator(GroupAwareRoleManager.getRolesForPrincipal) | ||
decorator = pmram.cache(PluggableAuthService__getGroupsForPrincipal_cachekey) | ||
PluggableAuthService._getGroupsForPrincipal = decorator(PluggableAuthService._getGroupsForPrincipal) | ||
# decorator = pmram.cache(PluggableAuthService__findUser_cachekey) | ||
# PluggableAuthService._findUser = decorator(PluggableAuthService._findUser) | ||
# decorator = pmram.cache(PluggableAuthService__verifyUser_cachekey) | ||
# PluggableAuthService._verifyUser = decorator(PluggableAuthService._verifyUser) | ||
decorator = pmram.cache(GroupsTool_getGroupById_cachekey) | ||
GroupsTool.getGroupById = decorator(GroupsTool.getGroupById) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" | ||
xmlns:tal="http://xml.zope.org/namespaces/tal" | ||
xmlns:metal="http://xml.zope.org/namespaces/metal" | ||
xmlns:i18n="http://xml.zope.org/namespaces/i18n" | ||
lang="en" | ||
metal:use-macro="context/prefs_main_template/macros/master" | ||
i18n:domain="plone.app.caching"> | ||
|
||
<body> | ||
|
||
<div metal:fill-slot="prefs_configlet_content"> | ||
|
||
<div id="region-content" class="documentEditable"> | ||
|
||
<div id="edit-bar"> | ||
<ul class="contentViews" id="content-views"> | ||
<li> | ||
<a href="" | ||
tal:attributes="href string:${portal_url}/@@caching-controlpanel" | ||
i18n:translate="label_settings">Change settings</a> | ||
</li> | ||
<li> | ||
<a href="" | ||
tal:attributes="href string:${portal_url}/@@caching-controlpanel-import" | ||
i18n:translate="label_import">Import settings</a> | ||
</li> | ||
<li tal:condition="view/purgingEnabled"> | ||
<a href="" | ||
tal:attributes="href string:${portal_url}/@@caching-controlpanel-purge" | ||
i18n:translate="label_purging">Purge caching proxy</a> | ||
</li> | ||
<li class="selected"> | ||
<a href="" | ||
tal:attributes="href string:${portal_url}/@@caching-controlpanel-ramcache" | ||
i18n:translate="label_ramcache">RAM cache</a> | ||
</li> | ||
</ul> | ||
</div> | ||
|
||
<div class="contentActions"> | ||
  | ||
</div> | ||
|
||
<div class="documentContent" id="content"> | ||
<a name="documentContent"></a> | ||
|
||
<div metal:use-macro="context/global_statusmessage/macros/portal_message"> | ||
Portal status message | ||
</div> | ||
|
||
<div class="configlet"> | ||
|
||
<h1 class="documentFirstHeading" | ||
i18n:translate="heading_ramcache_stats">RAM cache statistics</h1> | ||
|
||
<a href="" | ||
class="link-parent" | ||
tal:attributes="href string:${portal_url}/plone_control_panel" | ||
i18n:translate="label_up_to_plone_setup"> | ||
Up to Site Setup | ||
</a> | ||
|
||
<p i18n:translate="description_ramcache_stats"> | ||
The table below shows statistics for the default RAM | ||
cache. You can use the <em>Purge</em> button to manually | ||
clear the cache if you suspect there are stale items there. | ||
</p> | ||
|
||
<table tal:define="stats view/stats" | ||
class="listing faceted-table-results nosort" summary="RAM cache statistics" | ||
i18n:attributes="summary heading_ramcache_stats;"> | ||
<thead> | ||
<th> | ||
<span i18n:translate="label_cache_key">Key</span><br /> | ||
<span>Totals</span> | ||
</th> | ||
<th> | ||
<span i18n:translate="label_cache_hits">Hits</span><br /> | ||
<span tal:content="python: sum([data['hits'] for data in stats])"> </span> | ||
</th> | ||
<th> | ||
<span i18n:translate="label_cache_misses">Misses</span><br /> | ||
<span tal:content="python: sum([data['misses'] for data in stats])"> </span> | ||
</th> | ||
<th> | ||
<span i18n:translate="label_cache_size_bytes">Size (bytes)</span><br /> | ||
<span tal:content="python: sum([data['size'] for data in stats])"> </span> | ||
</th> | ||
<th> | ||
<span i18n:translate="label_cache_entries">Entries</span><br /> | ||
<span tal:content="python: sum([data['entries'] for data in stats])"> </span> | ||
</th> | ||
<th> | ||
<span i18n:translate="label_cache_entries">Older entry</span> | ||
</th> | ||
</thead> | ||
|
||
<tbody> | ||
<tr tal:repeat="data stats"> | ||
<td><span tal:content="data/path"> </span></td> | ||
<td><span tal:content="data/hits"> </span></td> | ||
<td><span tal:content="data/misses"> </span></td> | ||
<td><span tal:content="data/size"> </span></td> | ||
<td><span tal:content="data/entries"> </span></td> | ||
<td><span tal:content="python: data['older_date'] and data['older_date'].strftime('%Y/%m/%d %H:%M:%S')"> </span></td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
|
||
<form name="purge" tal:attributes="action string:${request/URL}" method="post" | ||
tal:define="errors view/errors"> | ||
|
||
<div class="formControls"> | ||
<input | ||
type="submit" | ||
name="form.button.Purge" | ||
class="destructive" | ||
value="Purge" | ||
i18n:attributes="value" /> | ||
</div> | ||
|
||
<input tal:replace="structure context/@@authenticator/authenticator" /> | ||
|
||
</form> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.