You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2017/12/11 02:50:06 UTC

[6/6] groovy git commit: Refine CommonCache and its javadoc

Refine CommonCache and its javadoc

(cherry picked from commit 61afa2a)


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

Branch: refs/heads/GROOVY_2_6_X
Commit: 319017d07cbb26e0f1dc96722f992559fe12d6cd
Parents: fecd7a6
Author: sunlan <su...@apache.org>
Authored: Mon Dec 11 10:46:12 2017 +0800
Committer: sunlan <su...@apache.org>
Committed: Mon Dec 11 10:49:50 2017 +0800

----------------------------------------------------------------------
 .../groovy/runtime/memoize/CommonCache.java     | 21 +++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/319017d0/src/main/org/codehaus/groovy/runtime/memoize/CommonCache.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/runtime/memoize/CommonCache.java b/src/main/org/codehaus/groovy/runtime/memoize/CommonCache.java
index f9cd925..1bd336d 100644
--- a/src/main/org/codehaus/groovy/runtime/memoize/CommonCache.java
+++ b/src/main/org/codehaus/groovy/runtime/memoize/CommonCache.java
@@ -44,19 +44,20 @@ public class CommonCache<K, V> implements EvictableCache<K, V> {
     private final ReentrantReadWriteLock.WriteLock writeLock = rwl.writeLock();
 
     /**
-     * A cache with unlimited size
+     * Constructs a cache with unlimited size
      */
     public CommonCache() {
         this(new LinkedHashMap<K, V>());
     }
 
     /**
-     * Another LRU cache, which is slower than {@link LRUCache} but will not put same value multi-times concurrently
+     * Constructs a cache with limited size
      * @param initialCapacity initial capacity of the LRU cache
      * @param maxSize max size of the LRU cache
+     * @param accessOrder the ordering mode - <tt>true</tt> for access-order, <tt>false</tt> for insertion-order, see the parameter accessOrder of {@link LinkedHashMap#LinkedHashMap(int, float, boolean)}
      */
-    public CommonCache(final int initialCapacity, final int maxSize) {
-        this(new LinkedHashMap<K, V>(initialCapacity, 0.75f, true) {
+    public CommonCache(final int initialCapacity, final int maxSize, final boolean accessOrder) {
+        this(new LinkedHashMap<K, V>(initialCapacity, 0.75f, accessOrder) {
             @Override
             protected boolean removeEldestEntry(Map.Entry<K, V> eldest) {
                 return size() > maxSize;
@@ -65,7 +66,17 @@ public class CommonCache<K, V> implements EvictableCache<K, V> {
     }
 
     /**
-     * Another LRU cache with the default initial capacity(16)
+     * Constructs a LRU cache with the specified initial capacity and max size.
+     * The LRU cache is slower than {@link LRUCache} but will not put same value multi-times concurrently
+     * @param initialCapacity initial capacity of the LRU cache
+     * @param maxSize max size of the LRU cache
+     */
+    public CommonCache(final int initialCapacity, final int maxSize) {
+        this(initialCapacity, maxSize, true);
+    }
+
+    /**
+     * Constructs a LRU cache with the default initial capacity(16)
      * @param maxSize max size of the LRU cache
      * @see #CommonCache(int, int)
      */