[infinispan-commits] Infinispan SVN: r2578 - in branches/4.2.x/core/src: main/java/org/infinispan/interceptors and 1 other directories.

infinispan-commits at lists.jboss.org infinispan-commits at lists.jboss.org
Fri Oct 22 10:36:42 EDT 2010


Author: sannegrinovero
Date: 2010-10-22 10:36:41 -0400 (Fri, 22 Oct 2010)
New Revision: 2578

Modified:
   branches/4.2.x/core/src/main/java/org/infinispan/context/Flag.java
   branches/4.2.x/core/src/main/java/org/infinispan/interceptors/CacheLoaderInterceptor.java
   branches/4.2.x/core/src/test/java/org/infinispan/loaders/UnnnecessaryLoadingTest.java
Log:
[ISPN-693] (Implement a SKIP_CACHE_LOAD flag to prevent loading an entry)

Modified: branches/4.2.x/core/src/main/java/org/infinispan/context/Flag.java
===================================================================
--- branches/4.2.x/core/src/main/java/org/infinispan/context/Flag.java	2010-10-22 14:22:21 UTC (rev 2577)
+++ branches/4.2.x/core/src/main/java/org/infinispan/context/Flag.java	2010-10-22 14:36:41 UTC (rev 2578)
@@ -88,6 +88,11 @@
     */
    SKIP_CACHE_STORE,
    /**
+    * Skips loading an entry from any configured {@link CacheStore}s. Useful for example to perform a put() operation
+    * while not interested in the return value of put() which would return the eventually existing previous value.
+    */
+   SKIP_CACHE_LOAD,
+   /**
     * Swallows any exceptions, logging them instead at a low log level.  Will prevent a failing operation from
     * affecting any ongoing JTA transactions as well.
     */

Modified: branches/4.2.x/core/src/main/java/org/infinispan/interceptors/CacheLoaderInterceptor.java
===================================================================
--- branches/4.2.x/core/src/main/java/org/infinispan/interceptors/CacheLoaderInterceptor.java	2010-10-22 14:22:21 UTC (rev 2577)
+++ branches/4.2.x/core/src/main/java/org/infinispan/interceptors/CacheLoaderInterceptor.java	2010-10-22 14:36:41 UTC (rev 2578)
@@ -121,9 +121,8 @@
    }
 
    private boolean loadIfNeeded(InvocationContext ctx, Object key) throws Throwable {
-      // in case SKIP_CACHE_STORE flag was enabled the operation is skipped
-      if (ctx.hasFlag(Flag.SKIP_CACHE_STORE)) {
-         return false;
+      if (ctx.hasFlag(Flag.SKIP_CACHE_STORE) || ctx.hasFlag(Flag.SKIP_CACHE_LOAD)) {
+         return false; //skip operation
       }
       // first check if the container contains the key we need.  Try and load this into the context.
       CacheEntry e = entryFactory.wrapEntryForReading(ctx, key);

Modified: branches/4.2.x/core/src/test/java/org/infinispan/loaders/UnnnecessaryLoadingTest.java
===================================================================
--- branches/4.2.x/core/src/test/java/org/infinispan/loaders/UnnnecessaryLoadingTest.java	2010-10-22 14:22:21 UTC (rev 2577)
+++ branches/4.2.x/core/src/test/java/org/infinispan/loaders/UnnnecessaryLoadingTest.java	2010-10-22 14:36:41 UTC (rev 2578)
@@ -47,10 +47,7 @@
 
    @Test
    public void testRepeatedLoads() throws CacheLoaderException {
-      CacheLoaderManager clm = TestingUtil.extractComponent(cache, CacheLoaderManager.class);
-      ChainingCacheStore ccs = (ChainingCacheStore) clm.getCacheLoader();
-      CountingCacheStore countingCS = (CountingCacheStore) ccs.getStores().keySet().iterator().next();
-      reset(cache,countingCS);
+      CountingCacheStore countingCS = getCountingCacheStore();
       store.store(InternalEntryFactory.create("k1", "v1"));
 
       assert countingCS.numLoads == 0;
@@ -69,10 +66,7 @@
 
    @Test
    public void testSkipCacheFlagUsage() throws CacheLoaderException {
-      CacheLoaderManager clm = TestingUtil.extractComponent(cache, CacheLoaderManager.class);
-      ChainingCacheStore ccs = (ChainingCacheStore) clm.getCacheLoader();
-      CountingCacheStore countingCS = (CountingCacheStore) ccs.getStores().keySet().iterator().next();
-      reset(cache, countingCS);
+      CountingCacheStore countingCS = getCountingCacheStore();
       
       store.store(InternalEntryFactory.create("k1", "v1"));
 
@@ -120,7 +114,34 @@
       assert countingCS.numLoads == 3 : "Expected 2, was " + countingCS.numLoads;
       cache.endBatch(true);
    }
+
+   private CountingCacheStore getCountingCacheStore() {
+      CacheLoaderManager clm = TestingUtil.extractComponent(cache, CacheLoaderManager.class);
+      ChainingCacheStore ccs = (ChainingCacheStore) clm.getCacheLoader();
+      CountingCacheStore countingCS = (CountingCacheStore) ccs.getStores().keySet().iterator().next();
+      reset(cache, countingCS);
+      return countingCS;
+   }
    
+   @Test
+   public void testSkipCacheLoadFlagUsage() throws CacheLoaderException {
+      CountingCacheStore countingCS = getCountingCacheStore();
+      
+      store.store(InternalEntryFactory.create("home", "Vermezzo"));
+      store.store(InternalEntryFactory.create("home-second", "Newcastle Upon Tyne"));
+
+      assert countingCS.numLoads == 0;
+      //load using SKIP_CACHE_LOAD should not find the object in the store
+      assert cache.getAdvancedCache().withFlags(Flag.SKIP_CACHE_LOAD).get("home") == null;
+      assert countingCS.numLoads == 0;
+      
+      assert cache.getAdvancedCache().withFlags(Flag.SKIP_CACHE_LOAD).put("home", "Newcastle") == null;
+      assert countingCS.numLoads == 0;
+      
+      assert "Newcastle Upon Tyne".equals(cache.getAdvancedCache().put("home-second", "Newcastle Upon Tyne, second"));
+      assert countingCS.numLoads == 1;
+   }
+   
    private void reset(Cache cache, CountingCacheStore countingCS) {
       cache.clear();
       countingCS.numLoads = 0;



More information about the infinispan-commits mailing list