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:46:19 UTC
groovy git commit: Refine CommonCache and its javadoc
Repository: groovy
Updated Branches:
refs/heads/master b2e8aa216 -> 61afa2a6b
Refine CommonCache and its javadoc
Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/61afa2a6
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/61afa2a6
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/61afa2a6
Branch: refs/heads/master
Commit: 61afa2a6bb17ad8e93af7af92d4d2a8bf1cfb281
Parents: b2e8aa2
Author: sunlan <su...@apache.org>
Authored: Mon Dec 11 10:46:12 2017 +0800
Committer: sunlan <su...@apache.org>
Committed: Mon Dec 11 10:46:12 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/61afa2a6/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)
*/