Changeset 17369 in josm for trunk/src/org/openstreetmap/josm/data/cache/JCSCacheManager.java
- Timestamp:
- 2020-11-27T22:45:55+01:00 (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/cache/JCSCacheManager.java
r17364 r17369 31 31 import org.openstreetmap.josm.data.preferences.IntegerProperty; 32 32 import org.openstreetmap.josm.spi.preferences.Config; 33 import org.openstreetmap.josm.tools.ImageResource;34 33 import org.openstreetmap.josm.tools.Logging; 35 34 import org.openstreetmap.josm.tools.Utils; … … 46 45 private static final String PREFERENCE_PREFIX = "jcs.cache"; 47 46 public static final BooleanProperty USE_BLOCK_CACHE = new BooleanProperty(PREFERENCE_PREFIX + ".use_block_cache", true); 48 49 /**50 * The preference key {@code jcs.cache.use_image_resource_cache} controls the caching mechanism used for {@link ImageResource}.51 * If set to {@code true}, a combined memory/disk is used. Otherwise, an in-memory-cache is used.52 */53 public static final BooleanProperty USE_IMAGE_RESOURCE_CACHE = new BooleanProperty(PREFERENCE_PREFIX + ".use_image_resource_cache", false);54 47 55 48 private static final AuxiliaryCacheFactory DISK_CACHE_FACTORY = … … 178 171 * @return cache access object 179 172 */ 173 @SuppressWarnings("unchecked") 180 174 public static <K, V> CacheAccess<K, V> getCache(String cacheName, int maxMemoryObjects, int maxDiskObjects, String cachePath) { 181 return getCache(cacheName, maxMemoryObjects, maxDiskObjects, cachePath, USE_BLOCK_CACHE.get() ? 4096 : 0);182 }183 184 @SuppressWarnings("unchecked")185 private static <K, V> CacheAccess<K, V> getCache(String cacheName, int maxMemoryObjects, int maxDiskObjects,186 String cachePath, int blockSizeBytes) {187 175 CacheAccess<K, V> cacheAccess = JCS.getInstance(cacheName, getCacheAttributes(maxMemoryObjects)); 188 176 CompositeCache<K, V> cc = cacheAccess.getCacheControl(); 189 177 190 178 if (cachePath != null && cacheDirLock != null) { 191 IDiskCacheAttributes diskAttributes = getDiskCacheAttributes(maxDiskObjects, cachePath, cacheName, blockSizeBytes); 192 Logging.debug("Setting up cache: {0}", diskAttributes); 179 IDiskCacheAttributes diskAttributes = getDiskCacheAttributes(maxDiskObjects, cachePath, cacheName); 193 180 try { 194 181 if (cc.getAuxCaches().length == 0) { … … 206 193 207 194 /** 208 * Returns a cache for {@link ImageResource}209 * @param <K> key type210 * @param <V> value type211 * @return cache access object212 */213 public static <K, V> CacheAccess<K, V> getImageResourceCache() {214 if (!USE_IMAGE_RESOURCE_CACHE.get()) {215 return getCache("images", 16 * 1024, 0, null);216 }217 String cachePath = new File(Config.getDirs().getCacheDirectory(true), "images").getAbsolutePath();218 Logging.warn("Using experimental disk cache {0} for ImageResource", cachePath);219 return getCache("images", 16 * 1024, 512 * 1024, cachePath, 1024);220 }221 222 /**223 195 * Close all files to ensure, that all indexes and data are properly written 224 196 */ … … 227 199 } 228 200 229 private static IDiskCacheAttributes getDiskCacheAttributes(int maxDiskObjects, String cachePath, String cacheName , int blockSizeBytes) {201 private static IDiskCacheAttributes getDiskCacheAttributes(int maxDiskObjects, String cachePath, String cacheName) { 230 202 IDiskCacheAttributes ret; 231 boolean isBlockDiskCache = blockSizeBytes > 0; 232 removeStaleFiles(cachePath + File.separator + cacheName, isBlockDiskCache ? "_INDEX_v2" : "_BLOCK_v2"); 233 String newCacheName = cacheName + (isBlockDiskCache ? "_BLOCK_v2" : "_INDEX_v2"); 234 235 if (isBlockDiskCache) { 203 removeStaleFiles(cachePath + File.separator + cacheName, USE_BLOCK_CACHE.get() ? "_INDEX_v2" : "_BLOCK_v2"); 204 String newCacheName = cacheName + (USE_BLOCK_CACHE.get() ? "_BLOCK_v2" : "_INDEX_v2"); 205 206 if (USE_BLOCK_CACHE.get()) { 236 207 BlockDiskCacheAttributes blockAttr = new BlockDiskCacheAttributes(); 237 208 /* … … 247 218 blockAttr.setMaxKeySize(maxDiskObjects); 248 219 } 249 blockAttr.setBlockSizeBytes( blockSizeBytes);220 blockAttr.setBlockSizeBytes(4096); // use 4k blocks 250 221 ret = blockAttr; 251 222 } else {
Note:
See TracChangeset
for help on using the changeset viewer.