You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by mr...@apache.org on 2016/07/26 21:18:15 UTC

[36/50] usergrid git commit: Fix additional cache issues to ensure we correctly re-use a single cache.

Fix additional cache issues to ensure we correctly re-use a single cache.


Project: http://git-wip-us.apache.org/repos/asf/usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/usergrid/commit/b11b3975
Tree: http://git-wip-us.apache.org/repos/asf/usergrid/tree/b11b3975
Diff: http://git-wip-us.apache.org/repos/asf/usergrid/diff/b11b3975

Branch: refs/heads/apigee-sso-provider
Commit: b11b397511b3894a3ab7f682178a5fced1c86ceb
Parents: a8f4218
Author: Michael Russo <mr...@apigee.com>
Authored: Thu Jul 14 11:32:28 2016 -0700
Committer: Michael Russo <mr...@apigee.com>
Committed: Thu Jul 14 11:32:28 2016 -0700

----------------------------------------------------------------------
 .../usergrid/corepersistence/CoreModule.java    |   3 +-
 .../corepersistence/CpEntityManager.java        |  53 ++++----
 .../corepersistence/CpEntityManagerFactory.java |   8 +-
 .../corepersistence/CpRelationManager.java      |  19 +--
 .../index/CollectionSettings.java               |  47 +++++++
 .../index/CollectionSettingsCache.java          |  50 +++++---
 .../index/CollectionSettingsCacheFactory.java   |  44 -------
 .../index/CollectionSettingsCacheImpl.java      | 122 -------------------
 .../index/CollectionSettingsFactory.java        |  89 ++++++++++++++
 .../index/CollectionSettingsImpl.java           |  92 ++++++++++++++
 .../index/CollectionSettingsScope.java          |  27 ++++
 .../index/CollectionSettingsScopeImpl.java      |  73 +++++++++++
 .../corepersistence/index/IndexServiceImpl.java |  17 ++-
 .../index/ReIndexServiceImpl.java               |  13 +-
 .../service/ApplicationServiceImpl.java         |  19 +--
 .../usergrid/persistence/cache/CacheScope.java  |  24 ++++
 .../impl/shard/DirectedEdgeMeta.java            |   8 +-
 17 files changed, 459 insertions(+), 249 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/b11b3975/stack/core/src/main/java/org/apache/usergrid/corepersistence/CoreModule.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CoreModule.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CoreModule.java
index ac51e9b..781eede 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CoreModule.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CoreModule.java
@@ -91,7 +91,8 @@ public class CoreModule extends AbstractModule {
 
         bind( ManagerCache.class ).to( CpManagerCache.class );
         bind( ApplicationIdCacheFactory.class );
-        bind( CollectionSettingsCacheFactory.class );
+        bind( CollectionSettingsFactory.class );
+        bind( CollectionSettingsCache.class );
 
 
         /**

http://git-wip-us.apache.org/repos/asf/usergrid/blob/b11b3975/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
index 41613ac..d80969c 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
@@ -29,8 +29,9 @@ import me.prettyprint.hector.api.query.QueryResult;
 import me.prettyprint.hector.api.query.SliceCounterQuery;
 import org.apache.commons.lang.NullArgumentException;
 import org.apache.usergrid.corepersistence.asyncevents.AsyncEventService;
-import org.apache.usergrid.corepersistence.index.CollectionSettingsCache;
-import org.apache.usergrid.corepersistence.index.CollectionSettingsCacheFactory;
+import org.apache.usergrid.corepersistence.index.CollectionSettings;
+import org.apache.usergrid.corepersistence.index.CollectionSettingsFactory;
+import org.apache.usergrid.corepersistence.index.CollectionSettingsScopeImpl;
 import org.apache.usergrid.corepersistence.service.CollectionService;
 import org.apache.usergrid.corepersistence.service.ConnectionService;
 import org.apache.usergrid.corepersistence.util.CpEntityMapUtils;
@@ -112,7 +113,7 @@ public class CpEntityManager implements EntityManager {
 
     private final ManagerCache managerCache;
 
-    private final CollectionSettingsCacheFactory collectionSettingsCacheFactory;
+    private final CollectionSettingsFactory collectionSettingsFactory;
 
     private final ApplicationScope applicationScope;
 
@@ -176,7 +177,7 @@ public class CpEntityManager implements EntityManager {
                             final GraphManagerFactory graphManagerFactory,
                             final CollectionService collectionService,
                             final ConnectionService connectionService,
-                            final CollectionSettingsCacheFactory collectionSettingsCacheFactory,
+                            final CollectionSettingsFactory collectionSettingsFactory,
                             final UUID applicationId ) {
 
         this.entityManagerFig = entityManagerFig;
@@ -201,7 +202,7 @@ public class CpEntityManager implements EntityManager {
         this.managerCache = managerCache;
         this.applicationId = applicationId;
         this.indexService = indexService;
-        this.collectionSettingsCacheFactory = collectionSettingsCacheFactory;
+        this.collectionSettingsFactory = collectionSettingsFactory;
 
         applicationScope = CpNamingUtils.getApplicationScope( applicationId );
 
@@ -550,10 +551,11 @@ public class CpEntityManager implements EntityManager {
     private boolean skipIndexingForType( String type ) {
 
         boolean skipIndexing = false;
-
-        MapManager mm = getMapManagerForTypes();
-        CollectionSettingsCache collectionSettingsCache = collectionSettingsCacheFactory.getInstance( mm );
         String collectionName = Schema.defaultCollectionName( type );
+
+
+        CollectionSettings collectionSettingsCache = collectionSettingsFactory
+            .getInstance( new CollectionSettingsScopeImpl(getAppIdObject(), collectionName) );
         Optional<Map<String, Object>> collectionSettings =
             collectionSettingsCache.getCollectionSettings( collectionName );
 
@@ -715,7 +717,7 @@ public class CpEntityManager implements EntityManager {
         Preconditions.checkNotNull(entityRef, "entityRef cannot be null");
 
         CpRelationManager relationManager = new CpRelationManager( managerCache, indexService, collectionService,
-            connectionService, this, entityManagerFig, applicationId, collectionSettingsCacheFactory, entityRef );
+            connectionService, this, entityManagerFig, applicationId, collectionSettingsFactory, entityRef );
         return relationManager;
     }
 
@@ -1120,9 +1122,10 @@ public class CpEntityManager implements EntityManager {
         }
 
         String region = null;
-        MapManager mm = getMapManagerForTypes();
-        CollectionSettingsCache collectionSettingsCache = collectionSettingsCacheFactory.getInstance( mm );
         String collectionName = Schema.defaultCollectionName( entityRef.getType() );
+
+        CollectionSettings collectionSettingsCache = collectionSettingsFactory
+            .getInstance( new CollectionSettingsScopeImpl( getAppIdObject(), collectionName) );
         Optional<Map<String, Object>> collectionSettings =
             collectionSettingsCache.getCollectionSettings( collectionName );
         if ( collectionSettings.isPresent() ) {
@@ -1771,10 +1774,8 @@ public class CpEntityManager implements EntityManager {
         // Possible values are app credentials, org credentials, or the user email(Admin tokens).
         updatedSettings.put( "lastUpdateBy", owner );
 
-        MapManager mm = getMapManagerForTypes();
-
-        CollectionSettingsCache collectionSettingsCache = collectionSettingsCacheFactory.getInstance( mm );
-
+        CollectionSettings collectionSettingsCache = collectionSettingsFactory
+            .getInstance( new CollectionSettingsScopeImpl( getAppIdObject(), collectionName) );
         Optional<Map<String, Object>> existingSettings =
             collectionSettingsCache.getCollectionSettings( collectionName );
 
@@ -1817,9 +1818,10 @@ public class CpEntityManager implements EntityManager {
 
     @Override
     public void deleteCollectionSettings( String collectionName ){
-        MapManager mm = getMapManagerForTypes();
 
-        CollectionSettingsCache collectionSettingsCache = collectionSettingsCacheFactory.getInstance( mm );
+        CollectionSettings collectionSettingsCache = collectionSettingsFactory
+            .getInstance( new CollectionSettingsScopeImpl( getAppIdObject(), collectionName) );
+
 
         collectionSettingsCache.deleteCollectionSettings( collectionName );
 
@@ -1828,12 +1830,12 @@ public class CpEntityManager implements EntityManager {
 
     @Override
     public Object getCollectionSettings(String collectionName) {
-        MapManager mm = getMapManagerForTypes();
 
-        CollectionSettingsCache collectionSettingsCache = collectionSettingsCacheFactory.getInstance( mm );
+        CollectionSettings collectionSettings =
+            collectionSettingsFactory.getInstance( new CollectionSettingsScopeImpl( getAppIdObject(), collectionName) );
 
         Optional<Map<String, Object>> collectionIndexingSchema =
-            collectionSettingsCache.getCollectionSettings( collectionName );
+            collectionSettings.getCollectionSettings( collectionName );
 
         if (collectionIndexingSchema.isPresent()) {
             return collectionIndexingSchema.get();
@@ -2469,6 +2471,10 @@ public class CpEntityManager implements EntityManager {
         return mm;
     }
 
+    private Id getAppIdObject(){
+        return new SimpleId( applicationId, TYPE_APPLICATION );
+    }
+
 
     @Override
     public <A extends Entity> A get( EntityRef entityRef, Class<A> entityClass ) throws Exception {
@@ -3108,11 +3114,12 @@ public class CpEntityManager implements EntityManager {
     private  String lookupRegionForType( String type ) {
 
         String region = null;
+        String collectionName = Schema.defaultCollectionName( type );
+
 
         // get collection settings for type
-        MapManager mm = getMapManagerForTypes();
-        CollectionSettingsCache collectionSettingsCache = collectionSettingsCacheFactory.getInstance( mm );
-        String collectionName = Schema.defaultCollectionName( type );
+        CollectionSettings collectionSettingsCache = collectionSettingsFactory
+            .getInstance( new CollectionSettingsScopeImpl( getAppIdObject(), collectionName) );
 
         Optional<Map<String, Object>> collectionSettings =
             collectionSettingsCache.getCollectionSettings( collectionName );

http://git-wip-us.apache.org/repos/asf/usergrid/blob/b11b3975/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
index e70a6fd..a419e58 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
@@ -26,7 +26,7 @@ import com.google.inject.Key;
 import com.google.inject.TypeLiteral;
 import org.apache.commons.lang.StringUtils;
 import org.apache.usergrid.corepersistence.asyncevents.AsyncEventService;
-import org.apache.usergrid.corepersistence.index.CollectionSettingsCacheFactory;
+import org.apache.usergrid.corepersistence.index.CollectionSettingsFactory;
 import org.apache.usergrid.corepersistence.index.ReIndexRequestBuilder;
 import org.apache.usergrid.corepersistence.index.ReIndexService;
 import org.apache.usergrid.corepersistence.service.CollectionService;
@@ -111,7 +111,7 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
     private final CollectionService collectionService;
     private final ConnectionService connectionService;
     private final GraphManagerFactory graphManagerFactory;
-    private final CollectionSettingsCacheFactory collectionSettingsCacheFactory;
+    private final CollectionSettingsFactory collectionSettingsFactory;
     private ActorSystemManager actorSystemManager;
     private UniqueValuesService uniqueValuesService;
     private final LockManager lockManager;
@@ -135,7 +135,7 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
         this.graphManagerFactory = injector.getInstance( GraphManagerFactory.class );
         this.collectionService = injector.getInstance( CollectionService.class );
         this.connectionService = injector.getInstance( ConnectionService.class );
-        this.collectionSettingsCacheFactory = injector.getInstance( CollectionSettingsCacheFactory.class );
+        this.collectionSettingsFactory = injector.getInstance( CollectionSettingsFactory.class );
 
         Properties properties = cassandraService.getProperties();
         this.entityManagers = createEntityManagerCache( properties );
@@ -378,7 +378,7 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
             graphManagerFactory,
             collectionService,
             connectionService,
-            collectionSettingsCacheFactory,
+            collectionSettingsFactory,
             applicationId );
 
         return em;

http://git-wip-us.apache.org/repos/asf/usergrid/blob/b11b3975/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpRelationManager.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpRelationManager.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpRelationManager.java
index c91816f..b398562 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpRelationManager.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpRelationManager.java
@@ -19,8 +19,9 @@ package org.apache.usergrid.corepersistence;
 
 import java.util.*;
 
-import org.apache.usergrid.corepersistence.index.CollectionSettingsCache;
-import org.apache.usergrid.corepersistence.index.CollectionSettingsCacheFactory;
+import org.apache.usergrid.corepersistence.index.CollectionSettings;
+import org.apache.usergrid.corepersistence.index.CollectionSettingsFactory;
+import org.apache.usergrid.corepersistence.index.CollectionSettingsScopeImpl;
 import org.apache.usergrid.corepersistence.results.IdQueryExecutor;
 import org.apache.usergrid.persistence.map.MapManager;
 import org.apache.usergrid.persistence.map.MapScope;
@@ -107,7 +108,7 @@ public class CpRelationManager implements RelationManager {
 
     private final AsyncEventService indexService;
 
-    private final CollectionSettingsCacheFactory collectionSettingsCacheFactory;
+    private final CollectionSettingsFactory collectionSettingsFactory;
 
 
     private final CollectionService collectionService;
@@ -119,7 +120,7 @@ public class CpRelationManager implements RelationManager {
                               final ConnectionService connectionService,
                               final EntityManager em,
                               final EntityManagerFig entityManagerFig, final UUID applicationId,
-                              final CollectionSettingsCacheFactory collectionSettingsCacheFactory,
+                              final CollectionSettingsFactory collectionSettingsFactory,
                               final EntityRef headEntity) {
 
 
@@ -159,7 +160,7 @@ public class CpRelationManager implements RelationManager {
             .format( "cpHeadEntity cannot be null for entity id %s, app id %s", entityId.getUuid(), applicationId ) );
 
         this.indexService = indexService;
-        this.collectionSettingsCacheFactory = collectionSettingsCacheFactory;
+        this.collectionSettingsFactory = collectionSettingsFactory;
 
     }
 
@@ -1106,11 +1107,13 @@ public class CpRelationManager implements RelationManager {
 
         boolean skipIndexing = false;
 
-        MapManager mm = getMapManagerForTypes();
-        CollectionSettingsCache collectionSettingsCache = collectionSettingsCacheFactory.getInstance( mm );
         String collectionName = Schema.defaultCollectionName( type );
+
+        CollectionSettings collectionSettings =
+            collectionSettingsFactory.
+                getInstance( new CollectionSettingsScopeImpl(new SimpleId( applicationId, TYPE_APPLICATION ), collectionName ) );
         Optional<Map<String, Object>> collectionIndexingSchema =
-            collectionSettingsCache.getCollectionSettings( collectionName );
+            collectionSettings.getCollectionSettings( collectionName );
 
         if ( collectionIndexingSchema.isPresent()) {
             Map jsonMapData = collectionIndexingSchema.get();

http://git-wip-us.apache.org/repos/asf/usergrid/blob/b11b3975/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/CollectionSettings.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/CollectionSettings.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/CollectionSettings.java
new file mode 100644
index 0000000..f5cccd5
--- /dev/null
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/CollectionSettings.java
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.usergrid.corepersistence.index;
+
+
+import java.util.Map;
+
+import com.google.common.base.Optional;
+
+
+public interface CollectionSettings {
+
+    /**
+     * Get the collection schema from the cache.
+     */
+    Optional<Map<String, Object>> getCollectionSettings(String collectionName );
+
+    void putCollectionSettings(String collectionName, String collectionSettings );
+
+    void deleteCollectionSettings(String collectionName );
+
+    /**
+     * Evict the collection schema from the cache.
+     */
+    //void evictCollectionSettings(String collectionName);
+
+    /**
+     * Evict everything from the cache.
+     */
+    //void evictCache();
+
+
+}

http://git-wip-us.apache.org/repos/asf/usergrid/blob/b11b3975/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/CollectionSettingsCache.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/CollectionSettingsCache.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/CollectionSettingsCache.java
index 941f7cc..1ff718e 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/CollectionSettingsCache.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/CollectionSettingsCache.java
@@ -1,3 +1,5 @@
+package org.apache.usergrid.corepersistence.index;
+
 /*
  * Licensed to the Apache Software Foundation (ASF) under one or more
  * contributor license agreements.  See the NOTICE file distributed with
@@ -14,34 +16,46 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.usergrid.corepersistence.index;
 
+import com.google.common.cache.Cache;
+import com.google.common.cache.CacheBuilder;
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+
+import java.util.concurrent.TimeUnit;
+
+@Singleton
+public class CollectionSettingsCache {
 
-import java.util.Map;
+    private final CollectionSettingsCacheFig fig;
+    private final Cache<CollectionSettingsScope,String> cache;
 
-import com.google.common.base.Optional;
 
+    @Inject
+    public CollectionSettingsCache( CollectionSettingsCacheFig fig ) {
+        this.fig = fig;
+        this.cache = CacheBuilder.newBuilder()
+            .maximumSize(Math.min(1000, fig.getCacheSize()))
+            .expireAfterWrite(fig.getCacheTimeout(), TimeUnit.SECONDS).build();
+    }
 
-public interface CollectionSettingsCache {
 
-    /**
-     * Get the collection schema from the cache.
-     */
-    Optional<Map<String, Object>> getCollectionSettings(String collectionName );
+    public void put(CollectionSettingsScope key, String value){
 
-    void putCollectionSettings(String collectionName, String collectionSettings );
+        cache.put(key, value);
+    }
 
-    void deleteCollectionSettings(String collectionName );
 
-    /**
-     * Evict the collection schema from the cache.
-     */
-    void evictCollectionSettings(String collectionName);
+    public String get(CollectionSettingsScope key){
+        return cache.getIfPresent(key);
+    }
 
-    /**
-     * Evict everything from the cache.
-     */
-    void evictCache();
+    public void invalidate(CollectionSettingsScope key){
+        cache.invalidate(key);
+    }
 
+    public void invalidateAll(){
+        cache.invalidateAll();
+    }
 
 }

http://git-wip-us.apache.org/repos/asf/usergrid/blob/b11b3975/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/CollectionSettingsCacheFactory.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/CollectionSettingsCacheFactory.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/CollectionSettingsCacheFactory.java
deleted file mode 100644
index 981f4ab..0000000
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/CollectionSettingsCacheFactory.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.usergrid.corepersistence.index;
-
-
-import org.apache.usergrid.persistence.map.MapManager;
-
-import com.google.inject.Inject;
-import com.google.inject.Singleton;
-
-
-/**
- * This can only be implemented after we have the impl for the application cache.
- */
-@Singleton
-public class CollectionSettingsCacheFactory {
-    private final CollectionSettingsCacheFig fig;
-
-    @Inject
-    public CollectionSettingsCacheFactory(CollectionSettingsCacheFig fig){
-        this.fig = fig;
-    }
-
-    public CollectionSettingsCache getInstance(MapManager mapManager ){
-        return new CollectionSettingsCacheImpl( mapManager,fig );
-    }
-
-
-}

http://git-wip-us.apache.org/repos/asf/usergrid/blob/b11b3975/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/CollectionSettingsCacheImpl.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/CollectionSettingsCacheImpl.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/CollectionSettingsCacheImpl.java
deleted file mode 100644
index d08e89a..0000000
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/CollectionSettingsCacheImpl.java
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.usergrid.corepersistence.index;
-
-
-import com.google.common.base.Optional;
-import com.google.common.cache.CacheBuilder;
-import com.google.common.cache.CacheLoader;
-import com.google.common.cache.LoadingCache;
-import com.google.inject.Singleton;
-import org.apache.usergrid.persistence.map.MapManager;
-import org.apache.usergrid.utils.JsonUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.util.Map;
-import java.util.concurrent.TimeUnit;
-
-
-/**
- * Cache collection settings to reduce load on Cassandra.
- */
-@Singleton
-public class CollectionSettingsCacheImpl implements CollectionSettingsCache {
-    private static final Logger logger = LoggerFactory.getLogger(CollectionSettingsCacheImpl.class );
-
-    private final LoadingCache<String,Optional<Map<String, Object>>> indexSchemaCache;
-    private final MapManager mapManager;
-
-
-    public CollectionSettingsCacheImpl( MapManager mapManager, CollectionSettingsCacheFig indexSchemaCacheFig) {
-        this.mapManager = mapManager;
-
-        indexSchemaCache = CacheBuilder.newBuilder()
-            .maximumSize( indexSchemaCacheFig.getCacheSize() )
-            .expireAfterWrite( indexSchemaCacheFig.getCacheTimeout(), TimeUnit.MILLISECONDS )
-            .build( new CacheLoader<String, Optional<Map<String, Object>>>() {
-                @Override
-                public Optional<Map<String, Object>> load( final String collectionName ) throws Exception {
-                    return Optional.fromNullable( retrieveCollectionSchema( collectionName ) );
-                }
-            } );
-    }
-
-    private Map retrieveCollectionSchema( final String collectionName ){
-        String collectionIndexingSchema = mapManager.getString( collectionName );
-        Map parsedCollectionIndexingSchema = null;
-        if(collectionIndexingSchema!=null){
-            return (Map) JsonUtils.parse( collectionIndexingSchema );
-
-        }
-        return parsedCollectionIndexingSchema;
-    }
-
-
-    @Override
-    public Optional<Map<String, Object>> getCollectionSettings(final String collectionName ) {
-
-        try {
-            Optional<Map<String, Object>> optionalCollectionSchema = indexSchemaCache.get( collectionName );
-            if(!optionalCollectionSchema.isPresent()){
-                indexSchemaCache.invalidate( collectionName );
-                return Optional.absent();
-            }
-            return optionalCollectionSchema;
-
-        } catch ( Exception e ) {
-            if(logger.isDebugEnabled()){
-                logger.debug( "Returning for collection name: {} "
-                    + "resulted in the following failure: {}",collectionName,e );
-            }
-        }
-        return null;
-    }
-
-    @Override
-    public void putCollectionSettings(final String collectionName, final String collectionSchema ){
-        mapManager.putString( collectionName, collectionSchema );
-        evictCollectionSettings( collectionName );
-    }
-
-
-    @Override
-    public void deleteCollectionSettings(final String collectionName){
-        mapManager.delete( collectionName );
-        evictCollectionSettings( collectionName );
-    }
-
-
-    @Override
-    public void evictCollectionSettings(final String collectionName ) {
-        indexSchemaCache.invalidate( collectionName );
-        if(logger.isDebugEnabled() ){
-            logger.debug( "Invalidated key {}",collectionName );
-        }
-
-    }
-
-
-    @Override
-    public void evictCache() {
-        indexSchemaCache.invalidateAll();
-        if(logger.isDebugEnabled()){
-            logger.debug( "Invalidated all keys" );
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/usergrid/blob/b11b3975/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/CollectionSettingsFactory.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/CollectionSettingsFactory.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/CollectionSettingsFactory.java
new file mode 100644
index 0000000..af4ae40
--- /dev/null
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/CollectionSettingsFactory.java
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.usergrid.corepersistence.index;
+
+
+import com.google.common.base.Optional;
+import com.google.common.cache.CacheBuilder;
+import com.google.common.cache.CacheLoader;
+import com.google.common.cache.LoadingCache;
+import org.apache.usergrid.corepersistence.util.CpNamingUtils;
+import org.apache.usergrid.persistence.map.MapManager;
+
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+import org.apache.usergrid.persistence.map.MapManagerFactory;
+import org.apache.usergrid.persistence.model.entity.Id;
+
+import java.util.Map;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
+
+
+/**
+ * This can only be implemented after we have the impl for the application cache.
+ */
+@Singleton
+public class CollectionSettingsFactory {
+
+    private final CollectionSettingsCacheFig fig;
+
+    private final MapManagerFactory mapManagerFactory;
+
+
+    private final LoadingCache<CollectionSettingsScope,CollectionSettings> indexSchemaCache;
+
+    private final CollectionSettingsCache collectionSettingsCache;
+
+
+    @Inject
+    public CollectionSettingsFactory( final CollectionSettingsCacheFig fig,
+                                      final MapManagerFactory mapManagerFactory,
+                                      final CollectionSettingsCache collectionSettingsCache ){
+        this.fig = fig;
+        this.mapManagerFactory = mapManagerFactory;
+        this.collectionSettingsCache = collectionSettingsCache;
+
+       indexSchemaCache  = CacheBuilder.newBuilder()
+            .maximumSize( fig.getCacheSize() )
+            .expireAfterWrite( fig.getCacheTimeout(), TimeUnit.MILLISECONDS )
+            .build( new CacheLoader<CollectionSettingsScope, CollectionSettings>() {
+                @Override
+                public CollectionSettings load( CollectionSettingsScope scope ) throws Exception {
+
+                    final MapManager mm = mapManagerFactory
+                        .createMapManager( CpNamingUtils.getEntityTypeMapScope(scope.getApplication()));
+                    return new CollectionSettingsImpl( scope, mm, collectionSettingsCache ) ;
+                }
+            } );
+    }
+
+
+    public CollectionSettings getInstance( CollectionSettingsScope scope ) {
+
+
+        try {
+            return indexSchemaCache.get(scope);
+        }catch (ExecutionException e){
+            throw new RuntimeException(e);
+        }
+
+    }
+
+
+}

http://git-wip-us.apache.org/repos/asf/usergrid/blob/b11b3975/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/CollectionSettingsImpl.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/CollectionSettingsImpl.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/CollectionSettingsImpl.java
new file mode 100644
index 0000000..921777a
--- /dev/null
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/CollectionSettingsImpl.java
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.usergrid.corepersistence.index;
+
+
+import com.google.common.base.Optional;
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+import org.apache.usergrid.persistence.map.MapManager;
+import org.apache.usergrid.utils.JsonUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Map;
+
+
+/**
+ * Cache collection settings to reduce load on Cassandra.
+ */
+public class CollectionSettingsImpl implements CollectionSettings {
+    private static final Logger logger = LoggerFactory.getLogger(CollectionSettingsImpl.class );
+
+    private final MapManager mapManager;
+    private final CollectionSettingsCache cache;
+    private final CollectionSettingsScope scope;
+
+    @Inject
+    public CollectionSettingsImpl( CollectionSettingsScope scope, MapManager mapManager, CollectionSettingsCache cache ) {
+        this.scope = scope;
+        this.mapManager = mapManager;
+        this.cache = cache;
+
+
+    }
+
+    @Override
+    public Optional<Map<String, Object>> getCollectionSettings(final String collectionName ) {
+
+        String settings;
+
+        settings = cache.get(scope);
+
+        if( settings == null ) {
+            settings = mapManager.getString(collectionName);
+
+        }
+
+        if (settings != null) {
+
+            if( settings.isEmpty() ){
+                return Optional.absent(); // empty string means it's empty.  we store empty string for cache purposes
+            }else{
+                return Optional.of((Map<String, Object>) JsonUtils.parse(settings));
+            }
+
+        }else{
+            cache.put(scope, ""); // store empty string here so empty is cached as well
+        }
+
+        return Optional.absent();
+    }
+
+    @Override
+    public void putCollectionSettings(final String collectionName, final String collectionSchema ){
+        mapManager.putString( collectionName, collectionSchema );
+        cache.put(scope, collectionSchema);
+    }
+
+
+    @Override
+    public void deleteCollectionSettings(final String collectionName){
+        mapManager.delete( collectionName );
+        cache.invalidate( scope );
+    }
+
+
+}

http://git-wip-us.apache.org/repos/asf/usergrid/blob/b11b3975/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/CollectionSettingsScope.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/CollectionSettingsScope.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/CollectionSettingsScope.java
new file mode 100644
index 0000000..73e451e
--- /dev/null
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/CollectionSettingsScope.java
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.usergrid.corepersistence.index;
+
+import org.apache.usergrid.persistence.core.scope.ApplicationScope;
+
+
+public interface CollectionSettingsScope extends ApplicationScope {
+
+
+    String getCollectionName();
+
+}

http://git-wip-us.apache.org/repos/asf/usergrid/blob/b11b3975/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/CollectionSettingsScopeImpl.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/CollectionSettingsScopeImpl.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/CollectionSettingsScopeImpl.java
new file mode 100644
index 0000000..a3f4c10
--- /dev/null
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/CollectionSettingsScopeImpl.java
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.usergrid.corepersistence.index;
+
+
+import org.apache.commons.lang.builder.HashCodeBuilder;
+import org.apache.usergrid.persistence.model.entity.Id;
+
+public class CollectionSettingsScopeImpl implements CollectionSettingsScope {
+
+    private final Id owner;
+    private final String collectionName;
+
+    public CollectionSettingsScopeImpl( final Id owner, final String collectionName ) {
+        this.owner = owner;
+        this.collectionName = collectionName;
+    }
+
+    @Override
+    public String getCollectionName() {
+        return collectionName;
+    }
+
+    @Override
+    public Id getApplication() {
+        return owner;
+    }
+
+    @Override
+    public boolean equals( final Object o ) {
+        if ( this == o ) {
+            return true;
+        }
+        if ( !( o instanceof CollectionSettingsScopeImpl ) ) {
+            return false;
+        }
+
+        final CollectionSettingsScopeImpl collectionSettingsScope = ( CollectionSettingsScopeImpl ) o;
+
+        if ( !collectionName.equals( collectionSettingsScope.collectionName ) ) {
+            return false;
+        }
+        if ( !owner.equals( collectionSettingsScope.owner ) ) {
+            return false;
+        }
+
+        return true;
+    }
+
+
+    @Override
+    public int hashCode() {
+        return new HashCodeBuilder()
+            .append(collectionName)
+            .append(owner)
+            .toHashCode();
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/usergrid/blob/b11b3975/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/IndexServiceImpl.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/IndexServiceImpl.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/IndexServiceImpl.java
index 43b00da..1b8614f 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/IndexServiceImpl.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/IndexServiceImpl.java
@@ -65,7 +65,7 @@ public class IndexServiceImpl implements IndexService {
     private final GraphManagerFactory graphManagerFactory;
     private final EntityIndexFactory entityIndexFactory;
     private final MapManagerFactory mapManagerFactory;
-    private final CollectionSettingsCacheFactory collectionSettingsCacheFactory;
+    private final CollectionSettingsFactory collectionSettingsFactory;
     private final EdgesObservable edgesObservable;
     private final IndexFig indexFig;
     private final IndexLocationStrategyFactory indexLocationStrategyFactory;
@@ -76,7 +76,7 @@ public class IndexServiceImpl implements IndexService {
     @Inject
     public IndexServiceImpl( final GraphManagerFactory graphManagerFactory, final EntityIndexFactory entityIndexFactory,
                              final MapManagerFactory mapManagerFactory,
-                             final CollectionSettingsCacheFactory collectionSettingsCacheFactory,
+                             final CollectionSettingsFactory collectionSettingsFactory,
                              final EdgesObservable edgesObservable, final IndexFig indexFig,
                              final IndexLocationStrategyFactory indexLocationStrategyFactory,
                              final MetricsFactory metricsFactory ) {
@@ -86,7 +86,7 @@ public class IndexServiceImpl implements IndexService {
         this.edgesObservable = edgesObservable;
         this.indexFig = indexFig;
         this.indexLocationStrategyFactory = indexLocationStrategyFactory;
-        this.collectionSettingsCacheFactory = collectionSettingsCacheFactory;
+        this.collectionSettingsFactory = collectionSettingsFactory;
         this.indexTimer = metricsFactory.getTimer( IndexServiceImpl.class, "index.update_all");
         this.addTimer = metricsFactory.getTimer( IndexServiceImpl.class, "index.add" );
     }
@@ -180,20 +180,17 @@ public class IndexServiceImpl implements IndexService {
      */
     private Optional<Set<String>> getFilteredStringObjectMap( final IndexEdge indexEdge ) {
 
-        Id mapOwner = new SimpleId( indexEdge.getNodeId().getUuid(), TYPE_APPLICATION );
-
-        final MapScope ms = CpNamingUtils.getEntityTypeMapScope( mapOwner );
-
-        MapManager mm = mapManagerFactory.createMapManager( ms );
+        Id owner = new SimpleId( indexEdge.getNodeId().getUuid(), TYPE_APPLICATION );
 
         Set<String> defaultProperties;
 
         String collectionName = CpNamingUtils.getCollectionNameFromEdgeName( indexEdge.getEdgeName() );
 
-        CollectionSettingsCache collectionSettingsCache = collectionSettingsCacheFactory.getInstance( mm );
+        CollectionSettings collectionSettings =
+            collectionSettingsFactory.getInstance( new CollectionSettingsScopeImpl( owner, collectionName) );
 
         Optional<Map<String, Object>> collectionIndexingSchema =
-            collectionSettingsCache.getCollectionSettings( collectionName );
+            collectionSettings.getCollectionSettings( collectionName );
 
         //If we do have a schema then parse it and add it to a list of properties we want to keep.Otherwise return.
         if ( collectionIndexingSchema.isPresent()) {

http://git-wip-us.apache.org/repos/asf/usergrid/blob/b11b3975/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/ReIndexServiceImpl.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/ReIndexServiceImpl.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/ReIndexServiceImpl.java
index 93e6b90..1093f3c 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/ReIndexServiceImpl.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/ReIndexServiceImpl.java
@@ -83,7 +83,7 @@ public class ReIndexServiceImpl implements ReIndexService {
     private final MapManagerFactory mapManagerFactory;
     private final AsyncEventService indexService;
     private final EntityIndexFactory entityIndexFactory;
-    private final CollectionSettingsCacheFactory collectionSettingsCacheFactory;
+    private final CollectionSettingsFactory collectionSettingsFactory;
 
 
     @Inject
@@ -93,7 +93,7 @@ public class ReIndexServiceImpl implements ReIndexService {
                                final MapManagerFactory mapManagerFactory,
                                final AllApplicationsObservable allApplicationsObservable,
                                final IndexProcessorFig indexProcessorFig,
-                               final CollectionSettingsCacheFactory collectionSettingsCacheFactory,
+                               final CollectionSettingsFactory collectionSettingsFactory,
                                final AsyncEventService indexService ) {
         this.entityIndexFactory = entityIndexFactory;
         this.indexLocationStrategyFactory = indexLocationStrategyFactory;
@@ -101,7 +101,7 @@ public class ReIndexServiceImpl implements ReIndexService {
         this.allApplicationsObservable = allApplicationsObservable;
         this.indexProcessorFig = indexProcessorFig;
         this.indexService = indexService;
-        this.collectionSettingsCacheFactory = collectionSettingsCacheFactory;
+        this.collectionSettingsFactory = collectionSettingsFactory;
         this.mapManagerFactory = mapManagerFactory;
         this.mapManager = mapManagerFactory.createMapManager( RESUME_MAP_SCOPE );
     }
@@ -141,11 +141,8 @@ public class ReIndexServiceImpl implements ReIndexService {
             String collectionName =  InflectionUtils.pluralize(
                 CpNamingUtils.getNameFromEdgeType(reIndexRequestBuilder.getCollectionName().get() ));
 
-            MapManager collectionMapStorage = mapManagerFactory.createMapManager(
-                CpNamingUtils.getEntityTypeMapScope( appId.get().getApplication()  ) );
-
-            CollectionSettingsCache collectionSettingsCache =
-                collectionSettingsCacheFactory.getInstance( collectionMapStorage );
+            CollectionSettings collectionSettingsCache =
+                collectionSettingsFactory.getInstance( new CollectionSettingsScopeImpl(appId.get().getApplication(), collectionName) );
 
             Optional<Map<String, Object>> collectionSettings =
                 collectionSettingsCache.getCollectionSettings( collectionName );

http://git-wip-us.apache.org/repos/asf/usergrid/blob/b11b3975/stack/core/src/main/java/org/apache/usergrid/corepersistence/service/ApplicationServiceImpl.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/service/ApplicationServiceImpl.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/service/ApplicationServiceImpl.java
index ea16d8b..9adb4f4 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/service/ApplicationServiceImpl.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/service/ApplicationServiceImpl.java
@@ -23,8 +23,9 @@ import com.google.common.base.Optional;
 import com.google.inject.Inject;
 import org.apache.usergrid.corepersistence.asyncevents.AsyncEventService;
 import org.apache.usergrid.corepersistence.asyncevents.EventBuilder;
-import org.apache.usergrid.corepersistence.index.CollectionSettingsCache;
-import org.apache.usergrid.corepersistence.index.CollectionSettingsCacheFactory;
+import org.apache.usergrid.corepersistence.index.CollectionSettings;
+import org.apache.usergrid.corepersistence.index.CollectionSettingsFactory;
+import org.apache.usergrid.corepersistence.index.CollectionSettingsScopeImpl;
 import org.apache.usergrid.corepersistence.rx.impl.AllEntityIdsObservable;
 import org.apache.usergrid.corepersistence.util.CpNamingUtils;
 import org.apache.usergrid.persistence.Schema;
@@ -60,7 +61,7 @@ public class ApplicationServiceImpl  implements ApplicationService{
     private final EventBuilder eventBuilder;
     private final MapManagerFactory mapManagerFactory;
     private final GraphManagerFactory graphManagerFactory;
-    private final CollectionSettingsCacheFactory collectionSettingsCacheFactory;
+    private final CollectionSettingsFactory collectionSettingsFactory;
     private final ActorSystemFig actorSystemFig;
 
 
@@ -71,7 +72,7 @@ public class ApplicationServiceImpl  implements ApplicationService{
                                   EventBuilder eventBuilder,
                                   MapManagerFactory mapManagerFactory,
                                   GraphManagerFactory graphManagerFactory,
-                                  CollectionSettingsCacheFactory collectionSettingsCacheFactory,
+                                  CollectionSettingsFactory collectionSettingsFactory,
                                   ActorSystemFig actorSystemFig
     ){
 
@@ -81,7 +82,7 @@ public class ApplicationServiceImpl  implements ApplicationService{
         this.eventBuilder = eventBuilder;
         this.mapManagerFactory = mapManagerFactory;
         this.graphManagerFactory = graphManagerFactory;
-        this.collectionSettingsCacheFactory = collectionSettingsCacheFactory;
+        this.collectionSettingsFactory = collectionSettingsFactory;
         this.actorSystemFig = actorSystemFig;
     }
 
@@ -151,11 +152,13 @@ public class ApplicationServiceImpl  implements ApplicationService{
 
         boolean skipIndexing = false;
 
-        MapManager mm = getMapManagerForTypes(applicationScope);
-        CollectionSettingsCache collectionSettingsCache = collectionSettingsCacheFactory.getInstance( mm );
         String collectionName = Schema.defaultCollectionName( type );
+
+        CollectionSettings collectionSettings = collectionSettingsFactory
+            .getInstance( new CollectionSettingsScopeImpl(applicationScope.getApplication(), collectionName));
+
         Optional<Map<String, Object>> collectionIndexingSchema =
-            collectionSettingsCache.getCollectionSettings( collectionName );
+            collectionSettings.getCollectionSettings( collectionName );
 
         if ( collectionIndexingSchema.isPresent()) {
             Map jsonMapData = collectionIndexingSchema.get();

http://git-wip-us.apache.org/repos/asf/usergrid/blob/b11b3975/stack/corepersistence/cache/src/main/java/org/apache/usergrid/persistence/cache/CacheScope.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/cache/src/main/java/org/apache/usergrid/persistence/cache/CacheScope.java b/stack/corepersistence/cache/src/main/java/org/apache/usergrid/persistence/cache/CacheScope.java
index 2440adc..f6b75b8 100644
--- a/stack/corepersistence/cache/src/main/java/org/apache/usergrid/persistence/cache/CacheScope.java
+++ b/stack/corepersistence/cache/src/main/java/org/apache/usergrid/persistence/cache/CacheScope.java
@@ -16,6 +16,7 @@
  */
 package org.apache.usergrid.persistence.cache;
 
+import org.apache.commons.lang.builder.HashCodeBuilder;
 import org.apache.usergrid.persistence.core.scope.ApplicationScope;
 import org.apache.usergrid.persistence.model.entity.Id;
 
@@ -35,4 +36,27 @@ public class CacheScope implements ApplicationScope {
     public Id getApplication() {
         return appId;
     }
+
+    @Override
+    public boolean equals( Object o){
+
+        if ( this == o ) {
+            return true;
+        }
+        if ( !( o instanceof CacheScope ) ) {
+            return false;
+        }
+
+        final CacheScope cacheScope = ( CacheScope ) o;
+
+        return appId.equals(cacheScope.appId);
+
+    }
+
+    @Override
+    public int hashCode(){
+        return new HashCodeBuilder()
+            .append(appId)
+            .toHashCode();
+    }
 }

http://git-wip-us.apache.org/repos/asf/usergrid/blob/b11b3975/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/impl/shard/DirectedEdgeMeta.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/impl/shard/DirectedEdgeMeta.java b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/impl/shard/DirectedEdgeMeta.java
index e7143bc..c4f5a9b 100644
--- a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/impl/shard/DirectedEdgeMeta.java
+++ b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/impl/shard/DirectedEdgeMeta.java
@@ -30,6 +30,7 @@ import java.util.Iterator;
 import java.util.Map;
 import java.util.UUID;
 
+import org.apache.commons.lang.builder.HashCodeBuilder;
 import org.apache.usergrid.persistence.core.scope.ApplicationScope;
 import org.apache.usergrid.persistence.graph.Edge;
 import org.apache.usergrid.persistence.graph.MarkedEdge;
@@ -119,9 +120,10 @@ public abstract class DirectedEdgeMeta {
 
         @Override
         public int hashCode() {
-            int result = id.hashCode();
-            result = 31 * result + nodeType.hashCode();
-            return result;
+            return new HashCodeBuilder()
+                .append(id)
+                .append(nodeType)
+                .toHashCode();
         }
     }