Changeset 16335 in josm for trunk/src/org/openstreetmap/josm


Ignore:
Timestamp:
2020-04-18T10:41:28+02:00 (4 years ago)
Author:
simon04
Message:

fix #19113 - Use JCS class instead of CompositeCacheManager

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/cache/JCSCacheManager.java

    r15926 r16335  
    1515import java.util.logging.SimpleFormatter;
    1616
     17import org.apache.commons.jcs.JCS;
    1718import org.apache.commons.jcs.access.CacheAccess;
    1819import org.apache.commons.jcs.auxiliary.AuxiliaryCache;
     
    2627import org.apache.commons.jcs.engine.behavior.ICompositeCacheAttributes.DiskUsagePattern;
    2728import org.apache.commons.jcs.engine.control.CompositeCache;
    28 import org.apache.commons.jcs.engine.control.CompositeCacheManager;
    2929import org.apache.commons.jcs.utils.serialization.StandardSerializer;
    3030import org.openstreetmap.josm.data.preferences.BooleanProperty;
     
    4242 */
    4343public final class JCSCacheManager {
    44     private static volatile CompositeCacheManager cacheManager;
    4544    private static final long maxObjectTTL = -1;
    4645    private static final String PREFERENCE_PREFIX = "jcs.cache";
     
    112111    }
    113112
    114     @SuppressWarnings("resource")
    115     private static void initialize() {
     113    static {
    116114        File cacheDir = new File(Config.getDirs().getCacheDirectory(true), "jcs");
    117115
     
    154152        // CHECKSTYLE.ON: SingleSpaceSeparator
    155153        try {
    156             CompositeCacheManager cm = CompositeCacheManager.getUnconfiguredInstance();
    157             cm.configure(props);
    158             cacheManager = cm;
     154            JCS.setConfigProperties(props);
    159155        } catch (SecurityException e) {
    160156            Logging.log(Logging.LEVEL_WARN, "Unable to initialize JCS", e);
     
    183179     * @return cache access object
    184180     */
     181    @SuppressWarnings("unchecked")
    185182    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();
    199185
    200186        if (cachePath != null && cacheDirLock != null) {
     
    203189                if (cc.getAuxCaches().length == 0) {
    204190                    cc.setAuxCaches(new AuxiliaryCache[]{DISK_CACHE_FACTORY.createCache(
    205                             diskAttributes, cacheManager, null, new StandardSerializer())});
     191                            diskAttributes, null, null, new StandardSerializer())});
    206192                }
    207193            } catch (Exception e) { // NOPMD
     
    211197            }
    212198        }
    213         return new CacheAccess<>(cc);
     199        return cacheAccess;
    214200    }
    215201
     
    218204     */
    219205    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();
    225207    }
    226208
Note: See TracChangeset for help on using the changeset viewer.