Ard Schrijvers pushed to branch feature/caching-psp1 at cms-community / 
hippo-site-toolkit


Commits:
b645a3d1 by Ard Schrijvers at 2016-12-01T15:35:53+01:00
HSTTWO-3877 clone the ehcache element when putting it in  second level cache

This way, a second level cache impl can modify the element to cache, for example
changing its TTL

- - - - -


1 changed file:

- 
components/core/src/main/java/org/hippoecm/hst/cache/ehcache/HstCacheEhCacheImpl.java


Changes:

=====================================
components/core/src/main/java/org/hippoecm/hst/cache/ehcache/HstCacheEhCacheImpl.java
=====================================
--- 
a/components/core/src/main/java/org/hippoecm/hst/cache/ehcache/HstCacheEhCacheImpl.java
+++ 
b/components/core/src/main/java/org/hippoecm/hst/cache/ehcache/HstCacheEhCacheImpl.java
@@ -230,7 +230,13 @@ public class HstCacheEhCacheImpl implements HstCache {
         CacheElementEhCacheImpl cacheElem = (CacheElementEhCacheImpl)element;
         ehcache.put(cacheElem.element);
         if (secondLevelCache != null) {
-            secondLevelCache.put(cacheElem.getKey(), cacheElem.element);
+            try {
+                // clone the element to cache first because the second level 
cache might change the TTL of the
+                // cached element
+                secondLevelCache.put(cacheElem.getKey(), 
cacheElem.element.clone());
+            } catch (CloneNotSupportedException e) {
+                log.warn("Could not clone '{}' : {}", 
cacheElem.element.getObjectKey(), e.toString());
+            }
         }
         if (staleCache != null) {
             staleCache.put(cacheElem.element.getObjectKey(), 
cacheElem.element);



View it on GitLab: 
https://code.onehippo.org/cms-community/hippo-site-toolkit/commit/b645a3d120d44cf21acba881ab9c12f9a0f31b1b
_______________________________________________
Hippocms-svn mailing list
Hippocms-svn@lists.onehippo.org
https://lists.onehippo.org/mailman/listinfo/hippocms-svn

Reply via email to