diff --git a/api/build.gradle b/api/build.gradle index 2be9f4fd3da..7bc7b8113b9 100644 --- a/api/build.gradle +++ b/api/build.gradle @@ -373,10 +373,10 @@ dependencies { BuildUtils.addExternalDependency( project, new ExternalDependency( - "net.sf.ehcache:ehcache-core:${ehcacheCoreVersion}", + "net.sf.ehcache:ehcache:${ehcacheVersion}", "Ehcache", "Terracotta", - "http://ehcache.org/documentation/overview.html", + "https://www.ehcache.org/", ExternalDependency.APACHE_2_LICENSE_NAME, ExternalDependency.APACHE_2_LICENSE_URL, "Caching library", diff --git a/api/src/org/labkey/api/cache/ehcache/EhCacheProvider.java b/api/src/org/labkey/api/cache/ehcache/EhCacheProvider.java index 1ccb8f00362..78d76a92007 100644 --- a/api/src/org/labkey/api/cache/ehcache/EhCacheProvider.java +++ b/api/src/org/labkey/api/cache/ehcache/EhCacheProvider.java @@ -26,9 +26,6 @@ import java.io.IOException; import java.io.InputStream; -import java.lang.ref.WeakReference; -import java.lang.reflect.Field; -import java.util.List; import java.util.concurrent.atomic.AtomicLong; /** @@ -43,8 +40,7 @@ public class EhCacheProvider implements CacheProvider private static final EhCacheProvider INSTANCE = new EhCacheProvider(); private final AtomicLong cacheCount = new AtomicLong(0); - private final SafeCacheManager MANAGER; - private final List> ehCacheReferenceList; + private final CacheManager MANAGER; public static EhCacheProvider getInstance() { @@ -53,37 +49,16 @@ public static EhCacheProvider getInstance() private EhCacheProvider() { - final CacheManager cm; try (InputStream is = EhCacheProvider.class.getResourceAsStream("ehcache.xml")) { - cm = new CacheManager(is); - MANAGER = new SafeCacheManager(cm); + MANAGER = new CacheManager(is); } catch (IOException e) { throw new RuntimeException(e); } - List> list; - - // Leave this in place to allow monitoring the size of the internal EhCache reference list. See #19480. - try - { - Field craField = cm.getClass().getDeclaredField("cacheRejoinAction"); - craField.setAccessible(true); - Object cra = craField.get(cm); - Field cachedField = cra.getClass().getDeclaredField("caches"); - cachedField.setAccessible(true); - list = (List>) cachedField.get(cra); - } - catch (NoSuchFieldException | IllegalAccessException e) - { - LOG.error("Could not access EhCache reference list via reflection", e); - list = null; - } - - ehCacheReferenceList = list; } @Override @@ -129,10 +104,6 @@ void closeCache(Cache cache) { MANAGER.removeCache(cache.getName()); - // We've upgraded EhCache to 2.6.8, so we no longer need to modify ehCacheReferenceList. Just log its size to keep us (and EhCache) honest. See #19480. - if (null != ehCacheReferenceList) - LOG.debug("Caches in EhCache reference list: {}", ehCacheReferenceList.size()); - LOG.debug("Closing \"{}\". Ehcaches: {}", cache.getName(), MANAGER.getCacheNames().length); } } diff --git a/api/src/org/labkey/api/cache/ehcache/EhSimpleCache.java b/api/src/org/labkey/api/cache/ehcache/EhSimpleCache.java index 7d08e28afc8..4e494f6968f 100644 --- a/api/src/org/labkey/api/cache/ehcache/EhSimpleCache.java +++ b/api/src/org/labkey/api/cache/ehcache/EhSimpleCache.java @@ -109,19 +109,19 @@ public int getLimit() @Override public int size() { - return (int)_cache.getStatistics().getObjectCount(); + return (int)_cache.getStatistics().getSize(); } @Override public int getExpirations() { - return (int)_cache.getLiveCacheStatistics().getExpiredCount(); + return (int)_cache.getStatistics().cacheExpiredCount(); } @Override public int getEvictions() { - return (int)_cache.getStatistics().getEvictionCount(); + return (int)_cache.getStatistics().cacheEvictedCount(); } @Override diff --git a/api/src/org/labkey/api/cache/ehcache/SafeCacheManager.java b/api/src/org/labkey/api/cache/ehcache/SafeCacheManager.java deleted file mode 100644 index e2fd1229c16..00000000000 --- a/api/src/org/labkey/api/cache/ehcache/SafeCacheManager.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) 2012 LabKey Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.labkey.api.cache.ehcache; - -import net.sf.ehcache.Cache; -import net.sf.ehcache.CacheManager; - -/** - * User: adam - * Date: 3/21/12 - * Time: 12:42 PM - */ - -// We've run into concurrency problems during the creation/deletion of EhCache instances, see #14387. EhCache is fixing -// this particular issue, but they recommend external synchronization, see https://jira.terracotta.org/jira/browse/EHC-931. -// This class implements that synchronization. -public class SafeCacheManager -{ - private final CacheManager _cacheManager; - - public SafeCacheManager(CacheManager cacheManager) - { - _cacheManager = cacheManager; - } - - public synchronized void shutdown() - { - _cacheManager.shutdown(); - } - - public synchronized void addCache(Cache ehCache) - { - _cacheManager.addCache(ehCache); - } - - public synchronized String[] getCacheNames() - { - return _cacheManager.getCacheNames(); - } - - public synchronized void removeCache(String name) - { - _cacheManager.removeCache(name); - } -}