Commits

chri...@81dbac14-341a-0410-aa85-cbcd92e6f43e  committed 37d0c35

[CACHE-118] Ensure we can still get hold of the previous cache entry so groups can be updated.

  • Participants
  • Parent commits 4edd63b

Comments (0)

Files changed (2)

File src/core/java/com/opensymphony/oscache/base/Cache.java

     public void putInCache(String key, Object content, String[] groups, EntryRefreshPolicy policy, String origin) {
         CacheEntry cacheEntry = this.getCacheEntry(key, policy, origin);
         boolean isNewEntry = cacheEntry.isNew();
+
+        // [CACHE-118] If we have a new entry, create a new CacheEntry so we can still access the old one later
+        if (!isNewEntry) {
+            cacheEntry = new CacheEntry(key, policy);
+        }
+
         cacheEntry.setContent(content);
         cacheEntry.setGroups(groups);
         cacheMap.put(key, cacheEntry);

File src/core/test/com/opensymphony/oscache/general/TestGeneralCacheAdministrator.java

     private static final int NB_CACHE_MISSED = 1;
     private static final int NB_ADD = 7;
     private static final int NB_UPDATED = 2;
-    private static final int NB_FLUSH = 4;
+    private static final int NB_FLUSH = 3;
     private static final int NB_REMOVED = 0;
     private static final int NB_GROUP_FLUSH = 2;
     private static final int NB_PATTERN_FLUSH = 1;
         admin.flushGroup(GROUP1); // Flushes item 2
         assertNotNull(checkObj("1", NO_REFRESH_NEEDED, false));
         assertNotNull(checkObj("2", NO_REFRESH_NEEDED, true));
+
+        // Test if regrouping a cache entry works
+        admin.putInCache("A", "ABC", new String[] {"A"});
+        admin.putInCache("A", "ABC", new String[] {"A", "B"});
+        admin.putInCache("B", "DEF", new String[] {"B"});
+        admin.flushGroup("B");
+        assertNotNull(checkObj("A", NO_REFRESH_NEEDED, true));
     }
 
     /**