Changeset 17364 in josm for trunk/src/org/openstreetmap/josm/data
- Timestamp:
- 2020-11-26T22:24:27+01:00 (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/cache/JCSCacheManager.java
r16401 r17364 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; 33 34 import org.openstreetmap.josm.tools.Logging; 34 35 import org.openstreetmap.josm.tools.Utils; … … 45 46 private static final String PREFERENCE_PREFIX = "jcs.cache"; 46 47 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); 47 54 48 55 private static final AuxiliaryCacheFactory DISK_CACHE_FACTORY = … … 171 178 * @return cache access object 172 179 */ 180 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 173 184 @SuppressWarnings("unchecked") 174 public static <K, V> CacheAccess<K, V> getCache(String cacheName, int maxMemoryObjects, int maxDiskObjects, String cachePath) { 185 private static <K, V> CacheAccess<K, V> getCache(String cacheName, int maxMemoryObjects, int maxDiskObjects, 186 String cachePath, int blockSizeBytes) { 175 187 CacheAccess<K, V> cacheAccess = JCS.getInstance(cacheName, getCacheAttributes(maxMemoryObjects)); 176 188 CompositeCache<K, V> cc = cacheAccess.getCacheControl(); 177 189 178 190 if (cachePath != null && cacheDirLock != null) { 179 IDiskCacheAttributes diskAttributes = getDiskCacheAttributes(maxDiskObjects, cachePath, cacheName); 191 IDiskCacheAttributes diskAttributes = getDiskCacheAttributes(maxDiskObjects, cachePath, cacheName, blockSizeBytes); 192 Logging.debug("Setting up cache: {0}", diskAttributes); 180 193 try { 181 194 if (cc.getAuxCaches().length == 0) { … … 193 206 194 207 /** 208 * Returns a cache for {@link ImageResource} 209 * @param <K> key type 210 * @param <V> value type 211 * @return cache access object 212 */ 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 /** 195 223 * Close all files to ensure, that all indexes and data are properly written 196 224 */ … … 199 227 } 200 228 201 private static IDiskCacheAttributes getDiskCacheAttributes(int maxDiskObjects, String cachePath, String cacheName ) {229 private static IDiskCacheAttributes getDiskCacheAttributes(int maxDiskObjects, String cachePath, String cacheName, int blockSizeBytes) { 202 230 IDiskCacheAttributes ret; 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()) { 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) { 207 236 BlockDiskCacheAttributes blockAttr = new BlockDiskCacheAttributes(); 208 237 /* … … 218 247 blockAttr.setMaxKeySize(maxDiskObjects); 219 248 } 220 blockAttr.setBlockSizeBytes( 4096); // use 4k blocks249 blockAttr.setBlockSizeBytes(blockSizeBytes); 221 250 ret = blockAttr; 222 251 } else {
Note:
See TracChangeset
for help on using the changeset viewer.