[Zope-CVS] CVS: Products/PluggableAuthService - PASCache.py:1.1.2.1 PluggableAuthService.py:1.19.2.1 __init__.py:1.4.2.1 utils.py:1.3.8.1

Jens Vagelpohl jens at dataflake.org
Tue Oct 19 07:45:10 EDT 2004


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

Modified Files:
      Tag: jens-implement_caching_branch
	PluggableAuthService.py __init__.py utils.py 
Added Files:
      Tag: jens-implement_caching_branch
	PASCache.py 
Log Message:
- checkpoint caching stuff on a branch



=== Added File Products/PluggableAuthService/PASCache.py ===
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights
# Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL).  A copy of the ZPL should accompany this
# distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
""" Classes: PASCacheable, PASRAMCacheManager

$Id: PASCache.py,v 1.1.2.1 2004/10/19 11:44:39 jens Exp $
"""

from Globals import InitializeClass
from AccessControl import ClassSecurityInfo
from OFS.Cache import Cacheable
from AccessControl.Permissions import manage_users
from Products.StandardCacheManagers.RAMCacheManager import RAMCacheManager
from Products.PageTemplates.PageTemplateFile import PageTemplateFile

class PASCacheable(Cacheable):

    security = ClassSecurityInfo()


InitializeClass(PASCacheable)


manage_addPASRAMCacheManagerForm = PageTemplateFile(
    'www/prcmAdd', globals(), __name__='manage_addPASRAMCacheManagerForm')

def addPASRAMCacheManager( dispatcher
                         , id
                         , REQUEST=None
                         ):
    """ Add a new PASRAMCacheManager to the PluggableAuthService """
    cache = PASRAMCacheManager(id)
    dispatcher._setObject(cache.getId(), cache)

    if REQUEST is not None:
        REQUEST['RESPONSE'].redirect( '%s/manage_workspace'
                                      '?manage_tabs_message='
                                      'PASRAMCacheManager+added.'
                                    % dispatcher.absolute_url() )

class PASRAMCacheManager(RAMCacheManager):

    meta_type = 'PAS RAM Cache Manager'

    security = ClassSecurityInfo()

    manage_stats = PageTemplateFile('www/prcmStats', globals())

    security.declareProtected(manage_users, 'manage_invalidate')
    def manage_invalidate(self, path, REQUEST=None):
        """ ZMI helper to invalidate an entry """
        try:
            ob = self.unrestrictedTraverse(path)
        except (AttributeError, KeyError):
            print 'Cannot delete', path

        ob.ZCacheable_invalidate()

        if REQUEST is not None:
            msg = 'Cache entry for %s invalidated' % path
            return self.manage_stats(manage_tabs_message=msg)


InitializeClass(PASRAMCacheManager)



=== Products/PluggableAuthService/PluggableAuthService.py 1.19 => 1.19.2.1 ===
--- Products/PluggableAuthService/PluggableAuthService.py:1.19	Sat Oct 16 16:15:47 2004
+++ Products/PluggableAuthService/PluggableAuthService.py	Tue Oct 19 07:44:39 2004
@@ -41,6 +41,7 @@
 from ZTUtils import Batch
 from App.class_init import default__class_init__ as InitializeClass
 from Products.PluginRegistry.PluginRegistry import PluginRegistry
+from Products.StandardCacheManagers.RAMCacheManager import RAMCacheManager
 import Products
 
 from interfaces.authservice import IUserFolder
@@ -67,6 +68,8 @@
 from permissions import SearchPrincipals
 
 from PropertiedUser import PropertiedUser
+from PASCache import PASRAMCacheManager
+from PASCache import PASCacheable
 from utils import _wwwdir
 
 
@@ -152,7 +155,7 @@
 InitializeClass( EmergencyUserAuthenticator )
 
 
-class PluggableAuthService( Folder ):
+class PluggableAuthService( Folder, PASCacheable ):
 
     """ All-singing, all-dancing user folder.
     """
@@ -196,9 +199,7 @@
         if not user_id:
             return None
 
-        return self._findUser( plugins, user_id, name
-                           # , cache=self._getUserCache()
-                             )
+        return self._findUser( plugins, user_id, name )
 
     security.declareProtected( ManageUsers, 'getUserById' )
     def getUserById( self, id, default=None ):
@@ -231,9 +232,7 @@
         if not user_id:
             return default
 
-        return self._findUser( plugins, user_id
-                           # , cache=self._getUserCache()
-                             )
+        return self._findUser( plugins, user_id )
 
     security.declarePublic( 'validate' )     # XXX: public?
     def validate( self, request, auth='', roles=_noroles ):
@@ -567,6 +566,7 @@
                         ,
                         )
                       + Folder.manage_options[2:]
+                      + PASCacheable.manage_options
                       )
 
     security.declareProtected(ManageUsers, 'resultsBatch')
@@ -844,10 +844,15 @@
         if user_id == self._emergency_user.getUserName():
             return self._emergency_user
 
-        if cache is None:
-            cache = {}
-
-        user = cache.get( user_id )
+        # See if the user can be retrieved from the cache
+        view_name = '_findUser-%s' % user_id
+        keywords = { 'user_id' : user_id
+                   , 'name' : name
+                   }
+        user = self.ZCacheable_get( view_name=view_name
+                                  , keywords=keywords
+                                  , default=None
+                                  )
 
         if user is None:
 
@@ -876,7 +881,12 @@
                     user._addRoles( roles )
 
             user._addRoles( ['Authenticated'] )
-            cache[ user_id ] = user
+
+            # Cache the user if caching is enabled
+            self.ZCacheable_set( aq_base(user)
+                               , view_name=view_name
+                               , keywords=keywords
+                               )
 
         return user.__of__( self )
 
@@ -1067,7 +1077,7 @@
     def all_meta_types(self):
         """ What objects can be put in here?
         """
-        allowed_types = tuple(MultiPlugins)
+        allowed_types = tuple(MultiPlugins) + (PASRAMCacheManager.meta_type,)
 
         return [x for x in Products.meta_types if x['name'] in allowed_types]
 


=== Products/PluggableAuthService/__init__.py 1.4 => 1.4.2.1 ===
--- Products/PluggableAuthService/__init__.py:1.4	Sat Oct 16 16:15:47 2004
+++ Products/PluggableAuthService/__init__.py	Tue Oct 19 07:44:39 2004
@@ -27,6 +27,8 @@
 
 import PluggableAuthService
 
+import PASCache
+
 from permissions import ManageGroups
 
 from plugins import HTTPBasicAuthHelper as HBAH
@@ -66,6 +68,15 @@
                          , constructors=(
                             PluggableAuthService.addPluggableAuthService, )
                          , icon='www/PluggableAuthService.png'
+                         )
+
+    context.registerClass( PASCache.PASRAMCacheManager
+                         , permission=ManageUsers
+                         , constructors=(
+                            PASCache.manage_addPASRAMCacheManagerForm,
+                            PASCache.addPASRAMCacheManager, )
+                         , visibility=None
+                         , icon='www/PASCache.png'
                          )
 
     context.registerClass( HBAH.HTTPBasicAuthHelper


=== Products/PluggableAuthService/utils.py 1.3 => 1.3.8.1 ===
--- Products/PluggableAuthService/utils.py:1.3	Thu Aug 12 11:15:53 2004
+++ Products/PluggableAuthService/utils.py	Tue Oct 19 07:44:39 2004
@@ -142,3 +142,11 @@
             suite.addTest( s )
 
     return suite
+
+def createViewName(method_name, user_handle):
+    """
+        Centralized place for creating the "View Name" that identifies
+        a ZCacheable record in a RAMCacheManager
+    """
+    return '%s-%s' % (method_name, user_handle)
+



More information about the Zope-CVS mailing list