Skip to content

Commit

Permalink
WW-5355 Update JavaDoc for basic and LRU cache
Browse files Browse the repository at this point in the history
  • Loading branch information
kusalk committed Oct 15, 2023
1 parent 1573207 commit 6ff7e15
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@
import java.util.concurrent.atomic.AtomicInteger;

/**
* Default OGNL cache implementation.
* <p>Basic OGNL cache implementation.</p>
*
* Setting a very high eviction limit simulates an unlimited cache.
* Setting too low an eviction limit will make the cache ineffective.
* <p>This implementation is backed by a {@link ConcurrentHashMap} that is cleared whenever the eviction limit is
* surpassed.</p>
*
* @param <Key> The type for the cache key entries
* <p>Setting a very high eviction limit simulates an unlimited cache.</p>
* <p>Setting too low an eviction limit will make the cache ineffective.</p>
*
* @param <Key> The type for the cache key entries
* @param <Value> The type for the cache value entries
*/
public class OgnlDefaultCache<Key, Value> implements OgnlCache<Key, Value> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@
import java.util.concurrent.atomic.AtomicInteger;

/**
* A basic OGNL LRU cache implementation.
* <p>A basic OGNL LRU cache implementation.</p>
*
* The implementation utilizes a {@link Collections#synchronizedMap(java.util.Map)}
* backed by a {@link LinkedHashMap}. May be replaced by a more efficient implementation in the future.
* <p>The implementation utilizes a {@link Collections#synchronizedMap(java.util.Map)}
* backed by a {@link LinkedHashMap}. May be replaced by a more efficient implementation in the future.</p>
*
* Setting too low an eviction limit will produce more overhead than value.
* Setting too high an eviction limit may also produce more overhead than value.
* An appropriate eviction limit will need to be determined on an individual application basis.
* <p>Setting too low an eviction limit will produce more overhead than value.</p>
* <p>Setting too high an eviction limit may also produce more overhead than value.</p>
* <p>An appropriate eviction limit will need to be determined on an individual application basis.</p>
*
* @param <Key> The type for the cache key entries
* @param <Key> The type for the cache key entries
* @param <Value> The type for the cache value entries
*/
public class OgnlLRUCache<Key, Value> implements OgnlCache<Key, Value> {
Expand All @@ -41,9 +41,9 @@ public class OgnlLRUCache<Key, Value> implements OgnlCache<Key, Value> {
public OgnlLRUCache(int evictionLimit, int initialCapacity, float loadFactor) {
cacheEvictionLimit = new AtomicInteger(evictionLimit);
// Access-order mode selected (order mode true in LinkedHashMap constructor).
ognlLRUCache = Collections.synchronizedMap (new LinkedHashMap<Key, Value>(initialCapacity, loadFactor, true) {
ognlLRUCache = Collections.synchronizedMap(new LinkedHashMap<Key, Value>(initialCapacity, loadFactor, true) {
@Override
protected boolean removeEldestEntry(Map.Entry<Key,Value> eldest) {
protected boolean removeEldestEntry(Map.Entry<Key, Value> eldest) {
return size() > cacheEvictionLimit.get();
}
});
Expand Down

0 comments on commit 6ff7e15

Please sign in to comment.