- Timestamp:
- 2020-04-18T10:41:28+02:00 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/cache/JCSCacheManager.java
r15926 r16335 15 15 import java.util.logging.SimpleFormatter; 16 16 17 import org.apache.commons.jcs.JCS; 17 18 import org.apache.commons.jcs.access.CacheAccess; 18 19 import org.apache.commons.jcs.auxiliary.AuxiliaryCache; … … 26 27 import org.apache.commons.jcs.engine.behavior.ICompositeCacheAttributes.DiskUsagePattern; 27 28 import org.apache.commons.jcs.engine.control.CompositeCache; 28 import org.apache.commons.jcs.engine.control.CompositeCacheManager;29 29 import org.apache.commons.jcs.utils.serialization.StandardSerializer; 30 30 import org.openstreetmap.josm.data.preferences.BooleanProperty; … … 42 42 */ 43 43 public final class JCSCacheManager { 44 private static volatile CompositeCacheManager cacheManager;45 44 private static final long maxObjectTTL = -1; 46 45 private static final String PREFERENCE_PREFIX = "jcs.cache"; … … 112 111 } 113 112 114 @SuppressWarnings("resource") 115 private static void initialize() { 113 static { 116 114 File cacheDir = new File(Config.getDirs().getCacheDirectory(true), "jcs"); 117 115 … … 154 152 // CHECKSTYLE.ON: SingleSpaceSeparator 155 153 try { 156 CompositeCacheManager cm = CompositeCacheManager.getUnconfiguredInstance(); 157 cm.configure(props); 158 cacheManager = cm; 154 JCS.setConfigProperties(props); 159 155 } catch (SecurityException e) { 160 156 Logging.log(Logging.LEVEL_WARN, "Unable to initialize JCS", e); … … 183 179 * @return cache access object 184 180 */ 181 @SuppressWarnings("unchecked") 185 182 public static <K, V> CacheAccess<K, V> getCache(String cacheName, int maxMemoryObjects, int maxDiskObjects, String cachePath) { 186 if (cacheManager != null) 187 return getCacheInner(cacheName, maxMemoryObjects, maxDiskObjects, cachePath); 188 189 synchronized (JCSCacheManager.class) { 190 if (cacheManager == null) 191 initialize(); 192 return cacheManager != null ? getCacheInner(cacheName, maxMemoryObjects, maxDiskObjects, cachePath) : null; 193 } 194 } 195 196 @SuppressWarnings("unchecked") 197 private static <K, V> CacheAccess<K, V> getCacheInner(String cacheName, int maxMemoryObjects, int maxDiskObjects, String cachePath) { 198 CompositeCache<K, V> cc = cacheManager.getCache(cacheName, getCacheAttributes(maxMemoryObjects)); 183 CacheAccess<K, V> cacheAccess = JCS.getInstance(cacheName, getCacheAttributes(maxMemoryObjects)); 184 CompositeCache<K, V> cc = cacheAccess.getCacheControl(); 199 185 200 186 if (cachePath != null && cacheDirLock != null) { … … 203 189 if (cc.getAuxCaches().length == 0) { 204 190 cc.setAuxCaches(new AuxiliaryCache[]{DISK_CACHE_FACTORY.createCache( 205 diskAttributes, cacheManager, null, new StandardSerializer())});191 diskAttributes, null, null, new StandardSerializer())}); 206 192 } 207 193 } catch (Exception e) { // NOPMD … … 211 197 } 212 198 } 213 return new CacheAccess<>(cc);199 return cacheAccess; 214 200 } 215 201 … … 218 204 */ 219 205 public static void shutdown() { 220 // use volatile semantics to get consistent object 221 CompositeCacheManager localCacheManager = cacheManager; 222 if (localCacheManager != null) { 223 localCacheManager.shutDown(); 224 } 206 JCS.shutdown(); 225 207 } 226 208
Note:
See TracChangeset
for help on using the changeset viewer.