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


Ignore:
Timestamp:
2015-04-10T14:06:46+02:00 (9 years ago)
Author:
bastiK
Message:

see #11312 - imagerycache Plugin broken by recent changes in JOSM (patch by wiktorn)

Location:
trunk/src/org/openstreetmap/josm
Files:
3 edited

Legend:

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

    r8172 r8186  
    33
    44import java.io.File;
     5import java.io.FileOutputStream;
    56import java.io.IOException;
     7import java.nio.channels.FileLock;
    68import java.text.MessageFormat;
    79import java.util.Properties;
     
    4042    private final static String PREFERENCE_PREFIX = "jcs.cache";
    4143    private final static IndexedDiskCacheFactory diskCacheFactory = new IndexedDiskCacheFactory();
     44    private static FileLock cacheDirLock = null;
    4245
    4346    /**
     
    4649    public static final IntegerProperty DEFAULT_MAX_OBJECTS_IN_MEMORY  = new IntegerProperty(PREFERENCE_PREFIX + ".max_objects_in_memory", 1000);
    4750
     51    @SuppressWarnings("resource")
    4852    private static void initialize() throws IOException {
    4953        File cacheDir = new File(Main.pref.getCacheDirectory(), "jcs");
     
    5155        if ((!cacheDir.exists() && !cacheDir.mkdirs()))
    5256            throw new IOException("Cannot access cache directory");
     57
     58        File cacheDirLockPath = new File(cacheDir, ".lock");
     59        if (!cacheDirLockPath.exists())
     60            cacheDirLockPath.createNewFile();
     61        cacheDirLock = new FileOutputStream(cacheDirLockPath).getChannel().tryLock();
     62
     63        if (cacheDirLock == null)
     64            log.log(Level.WARNING, "Cannot lock cache directory. Will not use disk cache");
    5365
    5466        // raising logging level gives ~500x performance gain
     
    139151        CompositeCache<K, V> cc = cacheManager.getCache(cacheName, getCacheAttributes(maxMemoryObjects));
    140152
    141         if (cachePath != null) {
     153        if (cachePath != null && cacheDirLock != null) {
    142154            IndexedDiskCacheAttributes diskAttributes = getDiskCacheAttributes(maxDiskObjects, cachePath);
    143155            diskAttributes.setCacheName(cacheName);
  • trunk/src/org/openstreetmap/josm/data/imagery/TMSCachedTileLoader.java

    r8174 r8186  
    6262
    6363    @Override
    64     public void clearCache() {
     64    public void clearCache(TileSource source) {
    6565        this.cache.clear();
    6666    }
  • trunk/src/org/openstreetmap/josm/gui/layer/TMSLayer.java

    r8168 r8186  
    194194        tileCache.clear();
    195195        if (tileLoader instanceof CachedTileLoader) {
    196             ((CachedTileLoader)tileLoader).clearCache();
     196            ((CachedTileLoader)tileLoader).clearCache(tileSource);
    197197        }
    198198    }
Note: See TracChangeset for help on using the changeset viewer.