You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by rm...@apache.org on 2014/05/30 19:24:18 UTC

svn commit: r1598677 - in /commons/proper/jcs/trunk/commons-jcs-jcache/src/main: java/org/apache/commons/jcs/jcache/JCSCache.java resources/jcache.ccf

Author: rmannibucau
Date: Fri May 30 17:24:17 2014
New Revision: 1598677

URL: http://svn.apache.org/r1598677
Log:
fixing bug found by hwaastad regarding expiry, created time rule is a bit different than update expiry in the jcs backend

Modified:
    commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/JCSCache.java
    commons/proper/jcs/trunk/commons-jcs-jcache/src/main/resources/jcache.ccf

Modified: commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/JCSCache.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/JCSCache.java?rev=1598677&r1=1598676&r2=1598677&view=diff
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/JCSCache.java (original)
+++ commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/JCSCache.java Fri May 30 17:24:17 2014
@@ -220,7 +220,7 @@ public class JCSCache<K, V> implements C
             final Duration duration = update ? expiryPolicy.getExpiryForUpdate() : expiryPolicy.getExpiryForCreation();
             if (isNotZero(duration))
             {
-                final ICacheElement<K, V> element = createElement(key, v, now, duration);
+                final ICacheElement<K, V> element = updateElement(key, v, duration);
                 try
                 {
                     delegate.update(element);
@@ -234,7 +234,7 @@ public class JCSCache<K, V> implements C
         return v;
     }
 
-    private ICacheElement<K, V> createElement(final K key, final V v, final long now, final Duration duration)
+    private ICacheElement<K, V> updateElement(final K key, final V v, final Duration duration)
     {
         final ICacheElement<K, V> element = new CacheElement<K, V>(name, key, v);
         final IElementAttributes copy = delegate.getElementAttributes().copy();
@@ -242,16 +242,12 @@ public class JCSCache<K, V> implements C
         {
             copy.setTimeFactorForMilliseconds(1);
             final boolean eternal = duration.isEternal();
-            if (eternal)
+            copy.setIsEternal(eternal);
+            if (!eternal)
             {
-                copy.setIsEternal(true);
-            }
-            else
-            {
-                copy.setIsEternal(false);
-                final long durationMs = duration.getTimeUnit().toMillis(duration.getDurationAmount());
-                copy.setIdleTime(durationMs);
+                copy.setIdleTime(duration.getTimeUnit().toMillis(duration.getDurationAmount()));
             }
+            // MaxLife = -1 to use IdleTime excepted if jcache.ccf asked for something else
         }
         element.setElementAttributes(copy);
         return element;
@@ -343,7 +339,19 @@ public class JCSCache<K, V> implements C
             final long start = Times.now(false);
 
             final K jcsKey = storeByValue ? copy(serializer, manager.getClassLoader(), key) : key;
-            final ICacheElement<K, V> element = createElement(jcsKey, value, start, duration);
+            final ICacheElement<K, V> element = updateElement(jcsKey, value, created ? null : duration); // reuse it to create basic structure
+            if (created && duration != null) { // set maxLife
+                final IElementAttributes copy = element.getElementAttributes();
+                copy.setTimeFactorForMilliseconds(1);
+                final boolean eternal = duration.isEternal();
+                copy.setIsEternal(eternal);
+                if (!eternal)
+                {
+                    copy.setIsEternal(false);
+                    element.getElementAttributes().setMaxLife(duration.getTimeUnit().toMillis(duration.getDurationAmount()));
+                }
+                element.setElementAttributes(copy);
+            }
             writer.write(new JCSEntry<K, V>(jcsKey, value));
             try
             {
@@ -484,7 +492,7 @@ public class JCSCache<K, V> implements C
             {
                 try
                 {
-                    delegate.update(createElement(key, v, getStart, expiryForAccess));
+                    delegate.update(updateElement(key, v, expiryForAccess));
                 }
                 catch (final IOException e)
                 {
@@ -542,7 +550,7 @@ public class JCSCache<K, V> implements C
             {
                 try
                 {
-                    delegate.update(createElement(key, elt.getVal(), getStart, expiryForAccess));
+                    delegate.update(updateElement(key, elt.getVal(), expiryForAccess));
                 }
                 catch (final IOException e)
                 {
@@ -589,7 +597,7 @@ public class JCSCache<K, V> implements C
                 {
                     try
                     {
-                        delegate.update(createElement(key, elt.getVal(), Times.now(false), expiryForAccess));
+                        delegate.update(updateElement(key, elt.getVal(), expiryForAccess));
                     }
                     catch (final IOException e)
                     {

Modified: commons/proper/jcs/trunk/commons-jcs-jcache/src/main/resources/jcache.ccf
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-jcache/src/main/resources/jcache.ccf?rev=1598677&r1=1598676&r2=1598677&view=diff
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-jcache/src/main/resources/jcache.ccf (original)
+++ commons/proper/jcs/trunk/commons-jcs-jcache/src/main/resources/jcache.ccf Fri May 30 17:24:17 2014
@@ -24,7 +24,7 @@ jcs.default.cacheattributes.MaxMemoryIdl
 jcs.default.cacheattributes.ShrinkerIntervalSeconds=60
 jcs.default.elementattributes=org.apache.commons.jcs.engine.ElementAttributes
 jcs.default.elementattributes.IsEternal=false
-jcs.default.elementattributes.MaxLifeSeconds=700
+jcs.default.elementattributes.MaxLife=700
 jcs.default.elementattributes.IdleTime=1800
 jcs.default.elementattributes.IsSpool=true
 jcs.default.elementattributes.IsRemote=true