Example usage for org.apache.commons.jcs.auxiliary.disk.indexed IndexedDiskCacheAttributes IndexedDiskCacheAttributes

List of usage examples for org.apache.commons.jcs.auxiliary.disk.indexed IndexedDiskCacheAttributes IndexedDiskCacheAttributes

Introduction

In this page you can find the example usage for org.apache.commons.jcs.auxiliary.disk.indexed IndexedDiskCacheAttributes IndexedDiskCacheAttributes.

Prototype

public IndexedDiskCacheAttributes() 

Source Link

Document

Constructor for the DiskCacheAttributes object

Usage

From source file:org.openstreetmap.josm.data.cache.JCSCacheManager.java

private static IDiskCacheAttributes getDiskCacheAttributes(int maxDiskObjects, String cachePath,
        String cacheName) {/*from w  ww  .jav  a 2 s .  co m*/
    IDiskCacheAttributes ret;
    removeStaleFiles(cachePath + File.separator + cacheName, USE_BLOCK_CACHE.get() ? "_INDEX_v2" : "_BLOCK_v2");
    String newCacheName = cacheName + (USE_BLOCK_CACHE.get() ? "_BLOCK_v2" : "_INDEX_v2");

    if (USE_BLOCK_CACHE.get()) {
        BlockDiskCacheAttributes blockAttr = new BlockDiskCacheAttributes();
        /*
         * 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 + newCacheName + ".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;
    } else {
        IndexedDiskCacheAttributes indexAttr = new IndexedDiskCacheAttributes();
        indexAttr.setMaxKeySize(maxDiskObjects);
        ret = indexAttr;
    }
    ret.setDiskLimitType(IDiskCacheAttributes.DiskLimitType.SIZE);
    File path = new File(cachePath);
    if (!path.exists() && !path.mkdirs()) {
        LOG.log(Level.WARNING, "Failed to create cache path: {0}", cachePath);
    } else {
        ret.setDiskPath(cachePath);
    }
    ret.setCacheName(newCacheName);

    return ret;
}