jodd.cache
Class FileLFUCache

java.lang.Object
  extended by jodd.cache.FileLFUCache

public class FileLFUCache
extends java.lang.Object

Files LFU cache stores files content in memory to dramatically speed up performances for frequently read files.


Field Summary
protected  LFUCache<java.io.File,byte[]> cache
           
protected  int maxFileSize
           
protected  int maxSize
           
protected  int usedSize
           
 
Constructor Summary
FileLFUCache(int maxSize)
          Creates file LFU cache with specified size.
FileLFUCache(int maxSize, int maxFileSize)
           
FileLFUCache(int maxSize, int maxFileSize, long timeout)
          Creates new File LFU cache.
 
Method Summary
 void clear()
          Clears the cache.
 int getCachedFilesCount()
          Returns number of cached files.
 long getCacheTimeout()
          Returns timeout.
 byte[] getFileBytes(java.io.File file)
          Returns cached file bytes.
 byte[] getFileBytes(java.lang.String fileName)
           
 int getMaxFileSize()
          Returns maximum allowed file size that can be added to the cache.
 int getMaxSize()
          Returns max cache size in bytes.
 int getUsedSize()
          Returns actually used size in bytes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cache

protected final LFUCache<java.io.File,byte[]> cache

maxSize

protected final int maxSize

maxFileSize

protected final int maxFileSize

usedSize

protected int usedSize
Constructor Detail

FileLFUCache

public FileLFUCache(int maxSize)
Creates file LFU cache with specified size. Sets max available file size to half of this value.


FileLFUCache

public FileLFUCache(int maxSize,
                    int maxFileSize)

FileLFUCache

public FileLFUCache(int maxSize,
                    int maxFileSize,
                    long timeout)
Creates new File LFU cache.

Parameters:
maxSize - total cache size in bytes
maxFileSize - max available file size in bytes, may be 0
timeout - timeout, may be 0
Method Detail

getMaxSize

public int getMaxSize()
Returns max cache size in bytes.


getUsedSize

public int getUsedSize()
Returns actually used size in bytes.


getMaxFileSize

public int getMaxFileSize()
Returns maximum allowed file size that can be added to the cache. Files larger than this value will be not added, even if there is enough room.


getCachedFilesCount

public int getCachedFilesCount()
Returns number of cached files.


getCacheTimeout

public long getCacheTimeout()
Returns timeout.


clear

public void clear()
Clears the cache.


getFileBytes

public byte[] getFileBytes(java.lang.String fileName)
                    throws java.io.IOException
Throws:
java.io.IOException

getFileBytes

public byte[] getFileBytes(java.io.File file)
                    throws java.io.IOException
Returns cached file bytes.

Throws:
java.io.IOException


Copyright © 2003-2012 Jodd Team