Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id C58AD200D65 for ; Mon, 11 Dec 2017 03:52:22 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id C439C160C09; Mon, 11 Dec 2017 02:52:22 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 1EEE9160C22 for ; Mon, 11 Dec 2017 03:52:21 +0100 (CET) Received: (qmail 21867 invoked by uid 500); 11 Dec 2017 02:52:21 -0000 Mailing-List: contact commits-help@groovy.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@groovy.apache.org Delivered-To: mailing list commits@groovy.apache.org Received: (qmail 21832 invoked by uid 99); 11 Dec 2017 02:52:21 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 11 Dec 2017 02:52:21 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id DAA68E080F; Mon, 11 Dec 2017 02:52:18 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: sunlan@apache.org To: commits@groovy.apache.org Date: Mon, 11 Dec 2017 02:52:23 -0000 Message-Id: <1f9e4f688f684f45adcae733c52a2026@git.apache.org> In-Reply-To: <030b3ae979314f5ba7bc0d8c3bba3257@git.apache.org> References: <030b3ae979314f5ba7bc0d8c3bba3257@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [6/6] groovy git commit: Refine CommonCache and its javadoc archived-at: Mon, 11 Dec 2017 02:52:22 -0000 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/8c0c94e8 Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/8c0c94e8 Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/8c0c94e8 Branch: refs/heads/GROOVY_2_5_X Commit: 8c0c94e82e6d40539989ca1f8a3d75e7e76bf7fc Parents: 303e831 Author: sunlan Authored: Mon Dec 11 10:46:12 2017 +0800 Committer: sunlan Committed: Mon Dec 11 10:52:07 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/8c0c94e8/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 implements EvictableCache { private final ReentrantReadWriteLock.WriteLock writeLock = rwl.writeLock(); /** - * A cache with unlimited size + * Constructs a cache with unlimited size */ public CommonCache() { this(new LinkedHashMap()); } /** - * 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 - true for access-order, false 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(initialCapacity, 0.75f, true) { + public CommonCache(final int initialCapacity, final int maxSize, final boolean accessOrder) { + this(new LinkedHashMap(initialCapacity, 0.75f, accessOrder) { @Override protected boolean removeEldestEntry(Map.Entry eldest) { return size() > maxSize; @@ -65,7 +66,17 @@ public class CommonCache implements EvictableCache { } /** - * 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) */