o changed the CacheService to not handle the various ADS cache instances
  (cause all such cache implementations cannot be moved to a single module e.x InmemoryReplayCache present in kerberos-shared)
o changed the way GroupCache is instantiated


git-svn-id: https://svn.apache.org/repos/asf/directory/apacheds/branches/apacheds-cache-experiment@978882 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/core-api/src/main/java/org/apache/directory/server/core/cache/CacheService.java b/core-api/src/main/java/org/apache/directory/server/core/cache/CacheService.java
index 728cadd..50327ff 100644
--- a/core-api/src/main/java/org/apache/directory/server/core/cache/CacheService.java
+++ b/core-api/src/main/java/org/apache/directory/server/core/cache/CacheService.java
@@ -49,12 +49,6 @@
     /** the ehcache cache manager */
     private CacheManager cacheManager;
 
-    /** directory service */
-    private DirectoryService dirService;
-
-    /** group cache */
-    private GroupCache groupCache;
-
 
     public CacheService()
     {
@@ -81,40 +75,27 @@
 
             cacheManager = new CacheManager( configFile.getAbsolutePath() );
         }
-
-        this.dirService = dirService;
     }
 
 
     public void destroy()
     {
-        if( cacheManager.getStatus() == Status.STATUS_ALIVE )
+        if ( cacheManager.getStatus() == Status.STATUS_ALIVE )
         {
             LOG.info( "destroying the cache service" );
-            
-            groupCache = null;
-            
+
             cacheManager.removalAll();
-            
+
             cacheManager.shutdown();
         }
     }
 
 
-    public GroupCache getGroupCache() throws LdapException
+    public Cache getCache( String name )
     {
-        if ( groupCache != null )
-        {
-            LOG.info( "returning the old group cache" );
-            return groupCache;
-        }
+        LOG.info( "fetching the cache named {}", name );
 
-        Cache ehCache = cacheManager.getCache( "groupCache" );
-        LOG.info( "creating a new group cache {}", ehCache.getStatus() );
-
-        groupCache = new GroupCache( dirService.getAdminSession(), ehCache );
-
-        return groupCache;
+        return cacheManager.getCache( name );
     }
 
 
diff --git a/core-api/src/main/java/org/apache/directory/server/core/cache/GroupCache.java b/core-api/src/main/java/org/apache/directory/server/core/cache/GroupCache.java
index 95eda02..9496405 100644
--- a/core-api/src/main/java/org/apache/directory/server/core/cache/GroupCache.java
+++ b/core-api/src/main/java/org/apache/directory/server/core/cache/GroupCache.java
@@ -31,6 +31,7 @@
 
 import org.apache.directory.server.constants.ServerDNConstants;
 import org.apache.directory.server.core.CoreSession;
+import org.apache.directory.server.core.DirectoryService;
 import org.apache.directory.server.core.filtering.EntryFilteringCursor;
 import org.apache.directory.server.core.interceptor.context.SearchOperationContext;
 import org.apache.directory.server.core.partition.PartitionNexus;
@@ -68,9 +69,6 @@
     /** Speedup for logs */
     private static final boolean IS_DEBUG = LOG.isDebugEnabled();
 
-    /** String key for the DN of a group to a Set (HashSet) for the Strings of member DNs */
-//    private final Map<String, Set<String>> groups = new HashMap<String, Set<String>>();
-
     /** a handle on the partition nexus */
     private final PartitionNexus nexus;
 
@@ -93,6 +91,7 @@
 
     private static final Set<DN> EMPTY_GROUPS = new HashSet<DN>();
 
+    /** String key for the DN of a group to a Set (HashSet) for the Strings of member DNs */
     private Cache ehCache;
 
     /**
@@ -101,10 +100,10 @@
      * @param directoryService the directory service core
      * @throws LdapException if there are failures on initialization 
      */
-    protected GroupCache( CoreSession session, Cache ehCache ) throws LdapException
+    public GroupCache( DirectoryService dirService ) throws LdapException
     {
-        schemaManager = session.getDirectoryService().getSchemaManager();
-        nexus = session.getDirectoryService().getPartitionNexus();
+        schemaManager = dirService.getSchemaManager();
+        nexus = dirService.getPartitionNexus();
         OBJECT_CLASS_AT = schemaManager.getAttributeType( SchemaConstants.OBJECT_CLASS_AT );
         MEMBER_AT = schemaManager.getAttributeType( SchemaConstants.MEMBER_AT );
         UNIQUE_MEMBER_AT = schemaManager.getAttributeType( SchemaConstants.UNIQUE_MEMBER_AT );
@@ -112,9 +111,9 @@
         // stuff for dealing with the admin group
         administratorsGroupDn = parseNormalized( ServerDNConstants.ADMINISTRATORS_GROUP_DN );
 
-        this.ehCache = ehCache;
+        this.ehCache = dirService.getCacheService().getCache( "groupCache" );
         
-        initialize( session );
+        initialize( dirService.getAdminSession() );
     }
 
 
diff --git a/core/src/main/java/org/apache/directory/server/core/authz/AciAuthorizationInterceptor.java b/core/src/main/java/org/apache/directory/server/core/authz/AciAuthorizationInterceptor.java
index bf8cef9..bb81ad3 100644
--- a/core/src/main/java/org/apache/directory/server/core/authz/AciAuthorizationInterceptor.java
+++ b/core/src/main/java/org/apache/directory/server/core/authz/AciAuthorizationInterceptor.java
@@ -198,7 +198,7 @@
 
         // Create the caches
         tupleCache = new TupleCache( adminSession );
-        groupCache = directoryService.getCacheService().getGroupCache();
+        groupCache = new GroupCache( directoryService );
 
         // look up some constant information
         OBJECT_CLASS_AT = schemaManager.getAttributeType( SchemaConstants.OBJECT_CLASS_AT );