[Zope-CVS] CVS: Products/PluggableAuthService/plugins - DynamicGroupsPlugin.py:1.4 ZODBUserManager.py:1.9

Jens Vagelpohl jens at dataflake.org
Mon Nov 8 17:36:15 EST 2004


Update of /cvs-repository/Products/PluggableAuthService/plugins
In directory cvs.zope.org:/tmp/cvs-serv5460/plugins

Modified Files:
	DynamicGroupsPlugin.py ZODBUserManager.py 
Log Message:
- merge the jens-implement_caching_branch . For some details please
  see doc/caching.stx.



=== Products/PluggableAuthService/plugins/DynamicGroupsPlugin.py 1.3 => 1.4 ===
--- Products/PluggableAuthService/plugins/DynamicGroupsPlugin.py:1.3	Thu Aug 12 11:15:54 2004
+++ Products/PluggableAuthService/plugins/DynamicGroupsPlugin.py	Mon Nov  8 17:35:45 2004
@@ -16,11 +16,14 @@
 
 $Id$
 """
+import copy
+
 from Acquisition import aq_inner, aq_parent
 from AccessControl import ClassSecurityInfo
 from OFS.SimpleItem import SimpleItem
 from OFS.PropertyManager import PropertyManager
 from OFS.Folder import Folder
+from OFS.Cache import Cacheable
 from Globals import InitializeClass
 from Persistence import PersistentMapping
 
@@ -37,6 +40,8 @@
 
 from Products.PluggableAuthService.plugins.BasePlugin import BasePlugin
 
+from Products.PluggableAuthService.utils import createViewName
+
 
 manage_addDynamicGroupsPluginForm = PageTemplateFile(
         'www/dgpAdd', globals(), __name__= 'manage_addDynamicGroupsPluginForm' )
@@ -157,7 +162,7 @@
 InitializeClass( DynamicGroupDefinition )
 
 
-class DynamicGroupsPlugin( Folder, BasePlugin ):
+class DynamicGroupsPlugin( Folder, BasePlugin, Cacheable ):
 
     """ Define groups via business rules.
 
@@ -210,6 +215,23 @@
         group_info = []
         group_ids = []
         plugin_id = self.getId()
+        view_name = createViewName('enumerateGroups', id)
+
+        # Look in the cache first...
+        keywords = copy.deepcopy(kw)
+        keywords.update( { 'id' : id
+                         , 'exact_match' : exact_match
+                         , 'sort_by' : sort_by
+                         , 'max_results' : max_results
+                         }
+                       )
+        cached_info = self.ZCacheable_get( view_name=view_name
+                                         , keywords=keywords
+                                         , default=None
+                                         )
+
+        if cached_info is not None:
+            return tuple(cached_info)
 
         if isinstance( id, str ):
             id = [ id ]
@@ -239,6 +261,9 @@
                 if info[ 'active' ]:
                     group_info.append( info )
 
+        # Put the computed value into the cache
+        self.ZCacheable_set(group_info, view_name=view_name, keywords=keywords)
+
         return tuple( group_info )
 
     #
@@ -322,6 +347,10 @@
                                      )
 
         self._setObject( group_id, info )
+
+        # This method changes the enumerateGroups return value
+        view_name = createViewName('enumerateGroups')
+        self.ZCacheable_invalidate(view_name=view_name)
             
     security.declareProtected( ManageGroups, 'updateGroup' )
     def updateGroup( self
@@ -354,6 +383,12 @@
 
         if active is not None:
             group.active = active
+
+        # This method changes the enumerateGroups return value
+        view_name = createViewName('enumerateGroups')
+        self.ZCacheable_invalidate(view_name=view_name)
+        view_name = createViewName('enumerateGroups', group_id)
+        self.ZCacheable_invalidate(view_name=view_name)
             
     security.declareProtected( ManageGroups, 'removeGroup' )
     def removeGroup( self, group_id ):
@@ -368,6 +403,12 @@
 
         self._delObject( group_id )
 
+        # This method changes the enumerateGroups return value
+        view_name = createViewName('enumerateGroups')
+        self.ZCacheable_invalidate(view_name=view_name)
+        view_name = createViewName('enumerateGroups', group_id)
+        self.ZCacheable_invalidate(view_name=view_name)
+
     #
     #   ZMI
     #
@@ -379,6 +420,7 @@
                      + Folder.manage_options[:1]
                      + BasePlugin.manage_options[:1]
                      + Folder.manage_options[1:]
+                     + Cacheable.manage_options
                      )
 
     manage_groups = PageTemplateFile( 'www/dgpGroups'


=== Products/PluggableAuthService/plugins/ZODBUserManager.py 1.8 => 1.9 ===
--- Products/PluggableAuthService/plugins/ZODBUserManager.py:1.8	Mon Nov  8 04:02:21 2004
+++ Products/PluggableAuthService/plugins/ZODBUserManager.py	Mon Nov  8 17:35:45 2004
@@ -17,14 +17,17 @@
 $Id$
 """
 import sha
+import copy
 
 from AccessControl import ClassSecurityInfo, AuthEncoding
 from AccessControl.SecurityManagement import getSecurityManager
 from App.class_init import default__class_init__ as InitializeClass
 from BTrees.OOBTree import OOBTree
+from OFS.Cache import Cacheable
 from Products.PageTemplates.PageTemplateFile import PageTemplateFile
 
 from Products.PluggableAuthService.plugins.BasePlugin import BasePlugin
+from Products.PluggableAuthService.utils import createViewName
 from Products.PluggableAuthService.interfaces.plugins \
     import IAuthenticationPlugin
 from Products.PluggableAuthService.interfaces.plugins \
@@ -35,6 +38,7 @@
 from Products.PluggableAuthService.permissions import ManageUsers
 from Products.PluggableAuthService.permissions import SetOwnPassword
 
+
 manage_addZODBUserManagerForm = PageTemplateFile(
     'www/zuAdd', globals(), __name__='manage_addZODBUserManagerForm' )
 
@@ -51,7 +55,7 @@
                                 'ZODBUserManager+added.'
                             % dispatcher.absolute_url())
 
-class ZODBUserManager( BasePlugin ):
+class ZODBUserManager( BasePlugin, Cacheable ):
 
     """ PAS plugin for managing users in the ZODB.
     """
@@ -127,6 +131,8 @@
         user_info = []
         user_ids = []
         plugin_id = self.getId()
+        view_name = createViewName('enumerateUsers', id or login)
+
 
         if isinstance( id, str ):
             id = [ id ]
@@ -134,6 +140,22 @@
         if isinstance( login, str ):
             login = [ login ]
 
+        # Look in the cache first...
+        keywords = copy.deepcopy(kw)
+        keywords.update( { 'id' : id
+                         , 'login' : login
+                         , 'exact_match' : exact_match
+                         , 'sort_by' : sort_by
+                         , 'max_results' : max_results
+                         }
+                       )
+        cached_info = self.ZCacheable_get( view_name=view_name
+                                         , keywords=keywords
+                                         , default=None
+                                         )
+        if cached_info is not None:
+            return tuple(cached_info)
+
         if exact_match and ( id or login ):
 
             if id:
@@ -164,6 +186,9 @@
                 if not user_filter or user_filter( info ):
                     user_info.append( info )
 
+        # Put the computed value into the cache
+        self.ZCacheable_set(user_info, view_name=view_name, keywords=keywords)
+
         return tuple( user_info )
 
     #
@@ -240,6 +265,10 @@
         self._login_to_userid[ login_name ] = user_id
         self._userid_to_login[ user_id ] = login_name
 
+        # enumerateUsers return value has changed
+        view_name = createViewName('enumerateUsers')
+        self.ZCacheable_invalidate(view_name=view_name)
+
     security.declarePrivate( 'removeUser' )
     def removeUser( self, user_id ):
 
@@ -252,6 +281,12 @@
         del self._login_to_userid[ login_name ]
         del self._userid_to_login[ user_id ]
 
+        # Also, remove from the cache
+        view_name = createViewName('enumerateUsers')
+        self.ZCacheable_invalidate(view_name=view_name)
+        view_name = createViewName('enumerateUsers', user_id)
+        self.ZCacheable_invalidate(view_name=view_name)
+
     security.declarePrivate( 'updateUserPassword' )
     def updateUserPassword( self, user_id, login_name, password ):
 
@@ -277,6 +312,7 @@
                          ,
                        )
                      + BasePlugin.manage_options
+                     + Cacheable.manage_options
                      )
 
     security.declarePublic( 'manage_widgets' )



More information about the Zope-CVS mailing list