Changeset 10652 in josm for trunk/src


Ignore:
Timestamp:
2016-07-26T22:06:52+02:00 (8 years ago)
Author:
wiktorn
Message:

Fix not using the calculated disk cache size.

Add unit tests for #13128 - using existing file size if greater than desired cache size.

Closes #13128

File:
1 edited

Legend:

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

    r10570 r10652  
    4545    private static long maxObjectTTL = -1;
    4646    private static final String PREFERENCE_PREFIX = "jcs.cache";
    47     public static BooleanProperty USE_BLOCK_CACHE = new BooleanProperty(PREFERENCE_PREFIX + ".use_block_cache", true);
     47    public static final BooleanProperty USE_BLOCK_CACHE = new BooleanProperty(PREFERENCE_PREFIX + ".use_block_cache", true);
    4848
    4949    private static final AuxiliaryCacheFactory diskCacheFactory =
     
    173173        if (cachePath != null && cacheDirLock != null) {
    174174            IDiskCacheAttributes diskAttributes = getDiskCacheAttributes(maxDiskObjects, cachePath, cacheName);
    175             /*
    176              * BlockDiskCache never optimizes the file, so when file size is reduced, it will never be truncated to desired size.
    177              *
    178              * If for some mysterious reason, file size is greater than the value set in preferences, just use the whole file. If the user
    179              * wants to reduce the file size, (s)he may just go to preferences and there it should be handled (by removing old file)
    180              */
    181             if (USE_BLOCK_CACHE.get()) {
    182                 File diskCacheFile = new File(cachePath + File.separator + diskAttributes.getCacheName() + ".data");
    183                 maxDiskObjects = (int) Math.max(maxDiskObjects, diskCacheFile.length()/1024);
    184             }
    185175            try {
    186176                if (cc.getAuxCaches().length == 0) {
     
    210200    private static IDiskCacheAttributes getDiskCacheAttributes(int maxDiskObjects, String cachePath, String cacheName) {
    211201        IDiskCacheAttributes ret;
     202        removeStaleFiles(cachePath + File.separator + cacheName, (USE_BLOCK_CACHE.get() ? "_INDEX_v2" : "_BLOCK_v2"));
     203        cacheName = cacheName + (USE_BLOCK_CACHE.get() ? "_BLOCK_v2" : "_INDEX_v2");
     204
    212205        if (USE_BLOCK_CACHE.get()) {
    213206            BlockDiskCacheAttributes blockAttr = new BlockDiskCacheAttributes();
    214             blockAttr.setMaxKeySize(maxDiskObjects);
     207            /*
     208             * BlockDiskCache never optimizes the file, so when file size is reduced, it will never be truncated to desired size.
     209             *
     210             * If for some mysterious reason, file size is greater than the value set in preferences, just use the whole file. If the user
     211             * wants to reduce the file size, (s)he may just go to preferences and there it should be handled (by removing old file)
     212             */
     213            File diskCacheFile = new File(cachePath + File.separator + cacheName + ".data");
     214            if (diskCacheFile.exists()) {
     215                blockAttr.setMaxKeySize((int) Math.max(maxDiskObjects, diskCacheFile.length()/1024));
     216            } else {
     217                blockAttr.setMaxKeySize(maxDiskObjects);
     218            }
    215219            blockAttr.setBlockSizeBytes(4096); // use 4k blocks
    216220            ret = blockAttr;
     
    227231            ret.setDiskPath(cachePath);
    228232        }
    229         ret.setCacheName(cacheName + (USE_BLOCK_CACHE.get() ? "_BLOCK_v2" : "_INDEX_v2"));
    230 
    231         removeStaleFiles(cachePath + File.separator + cacheName, (USE_BLOCK_CACHE.get() ? "_INDEX_v2" : "_BLOCK_v2"));
     233        ret.setCacheName(cacheName);
     234
    232235        return ret;
    233236    }
Note: See TracChangeset for help on using the changeset viewer.