diff --git a/uberfire-services/uberfire-services-api/src/main/java/org/guvnor/common/services/backend/cache/LRUCache.java b/uberfire-services/uberfire-services-api/src/main/java/org/guvnor/common/services/backend/cache/LRUCache.java index 456a289fa9..33b1fdc538 100644 --- a/uberfire-services/uberfire-services-api/src/main/java/org/guvnor/common/services/backend/cache/LRUCache.java +++ b/uberfire-services/uberfire-services-api/src/main/java/org/guvnor/common/services/backend/cache/LRUCache.java @@ -32,14 +32,11 @@ public abstract class LRUCache implements Cache { private Map cache; public LRUCache() { - cache = new LinkedHashMap(MAX_ENTRIES + 1, - 0.75f, - true) { - public boolean removeEldestEntry(Map.Entry eldest) { - return size() > MAX_ENTRIES; - } - }; - cache = (Map) Collections.synchronizedMap(cache); + setCache(MAX_ENTRIES); + } + + public LRUCache(final int maxEntries) { + setCache(maxEntries); } @Override @@ -75,4 +72,15 @@ public void invalidateCache(final Path path) { public Set getKeys() { return cache.keySet(); } + + private void setCache(final int maxEntries) { + cache = new LinkedHashMap(maxEntries + 1, + 0.75f, + true) { + public boolean removeEldestEntry(Map.Entry eldest) { + return size() > maxEntries; + } + }; + cache = (Map) Collections.synchronizedMap(cache); + } }