Index: trunk/src/org/openstreetmap/josm/data/cache/JCSCacheManager.java
===================================================================
--- trunk/src/org/openstreetmap/josm/data/cache/JCSCacheManager.java	(revision 10651)
+++ trunk/src/org/openstreetmap/josm/data/cache/JCSCacheManager.java	(revision 10652)
@@ -45,5 +45,5 @@
     private static long maxObjectTTL = -1;
     private static final String PREFERENCE_PREFIX = "jcs.cache";
-    public static BooleanProperty USE_BLOCK_CACHE = new BooleanProperty(PREFERENCE_PREFIX + ".use_block_cache", true);
+    public static final BooleanProperty USE_BLOCK_CACHE = new BooleanProperty(PREFERENCE_PREFIX + ".use_block_cache", true);
 
     private static final AuxiliaryCacheFactory diskCacheFactory =
@@ -173,14 +173,4 @@
         if (cachePath != null && cacheDirLock != null) {
             IDiskCacheAttributes diskAttributes = getDiskCacheAttributes(maxDiskObjects, cachePath, cacheName);
-            /*
-             * BlockDiskCache never optimizes the file, so when file size is reduced, it will never be truncated to desired size.
-             *
-             * If for some mysterious reason, file size is greater than the value set in preferences, just use the whole file. If the user
-             * wants to reduce the file size, (s)he may just go to preferences and there it should be handled (by removing old file)
-             */
-            if (USE_BLOCK_CACHE.get()) {
-                File diskCacheFile = new File(cachePath + File.separator + diskAttributes.getCacheName() + ".data");
-                maxDiskObjects = (int) Math.max(maxDiskObjects, diskCacheFile.length()/1024);
-            }
             try {
                 if (cc.getAuxCaches().length == 0) {
@@ -210,7 +200,21 @@
     private static IDiskCacheAttributes getDiskCacheAttributes(int maxDiskObjects, String cachePath, String cacheName) {
         IDiskCacheAttributes ret;
+        removeStaleFiles(cachePath + File.separator + cacheName, (USE_BLOCK_CACHE.get() ? "_INDEX_v2" : "_BLOCK_v2"));
+        cacheName = cacheName + (USE_BLOCK_CACHE.get() ? "_BLOCK_v2" : "_INDEX_v2");
+
         if (USE_BLOCK_CACHE.get()) {
             BlockDiskCacheAttributes blockAttr = new BlockDiskCacheAttributes();
-            blockAttr.setMaxKeySize(maxDiskObjects);
+            /*
+             * BlockDiskCache never optimizes the file, so when file size is reduced, it will never be truncated to desired size.
+             *
+             * If for some mysterious reason, file size is greater than the value set in preferences, just use the whole file. If the user
+             * wants to reduce the file size, (s)he may just go to preferences and there it should be handled (by removing old file)
+             */
+            File diskCacheFile = new File(cachePath + File.separator + cacheName + ".data");
+            if (diskCacheFile.exists()) {
+                blockAttr.setMaxKeySize((int) Math.max(maxDiskObjects, diskCacheFile.length()/1024));
+            } else {
+                blockAttr.setMaxKeySize(maxDiskObjects);
+            }
             blockAttr.setBlockSizeBytes(4096); // use 4k blocks
             ret = blockAttr;
@@ -227,7 +231,6 @@
             ret.setDiskPath(cachePath);
         }
-        ret.setCacheName(cacheName + (USE_BLOCK_CACHE.get() ? "_BLOCK_v2" : "_INDEX_v2"));
-
-        removeStaleFiles(cachePath + File.separator + cacheName, (USE_BLOCK_CACHE.get() ? "_INDEX_v2" : "_BLOCK_v2"));
+        ret.setCacheName(cacheName);
+
         return ret;
     }
Index: trunk/test/unit/org/openstreetmap/josm/data/cache/JCSCacheManagerTest.java
===================================================================
--- trunk/test/unit/org/openstreetmap/josm/data/cache/JCSCacheManagerTest.java	(revision 10651)
+++ trunk/test/unit/org/openstreetmap/josm/data/cache/JCSCacheManagerTest.java	(revision 10652)
@@ -2,7 +2,13 @@
 package org.openstreetmap.josm.data.cache;
 
+import static org.junit.Assert.assertEquals;
+
+import java.io.File;
+import java.io.FileOutputStream;
 import java.io.IOException;
 import java.util.logging.Logger;
 
+import org.apache.commons.jcs.access.CacheAccess;
+import org.apache.commons.jcs.auxiliary.disk.block.BlockDiskCacheAttributes;
 import org.junit.BeforeClass;
 import org.junit.Test;
@@ -31,3 +37,23 @@
         Logger.getLogger("org.apache.commons.jcs").warning("{switch:0}");
     }
+
+    @Test
+    public void testUseBigDiskFile() throws IOException {
+        if (JCSCacheManager.USE_BLOCK_CACHE.get()) {
+            // test only when using block cache
+            File cacheFile = new File("foobar/testUseBigDiskFile_BLOCK_v2.data");
+            if (!cacheFile.exists()) {
+                cacheFile.createNewFile();
+            }
+            try (FileOutputStream fileOutputStream = new FileOutputStream(cacheFile, false)) {
+                fileOutputStream.getChannel().truncate(0);
+                fileOutputStream.write(new byte[1024*1024*10]); // create 10MB empty file
+            }
+
+            CacheAccess<Object, Object> cache = JCSCacheManager.getCache("testUseBigDiskFile", 1, 100, "foobar");
+            assertEquals("BlockDiskCache use file size to calculate its size", 10*1024,
+                    ((BlockDiskCacheAttributes)cache.getCacheControl().getAuxCaches()[0].getAuxiliaryCacheAttributes()).getMaxKeySize());
+        }
+    }
+
 }
