Class FileCacheManager

java.lang.Object
ch.autumo.commons.cache.FileCacheManager

public class FileCacheManager extends Object
File cache manager.
  • Field Details

    • LOG

      protected static final org.slf4j.Logger LOG
      Logger.
    • MAX_CACHE_SIZE

      public static final long MAX_CACHE_SIZE
      Max file cache size in bytes.
  • Method Details

    • getInstance

      public static FileCacheManager getInstance()
      File cache manager.
      Returns:
      file manager
    • getSize

      public long getSize()
      Get size of cache.
      Returns:
      cache size
    • hasSpace

      public boolean hasSpace(long oldValueInBytes, long newValueInBytes)
      Is there space left in the cache?
      Parameters:
      oldValueInBytes - old amount of bytes that have been used for the sam resource
      newValueInBytes - new amount of bytes that is used by the changed resource
      Returns:
      true, is there is space, otherwise false
    • updateCacheSize

      public long updateCacheSize(long oldValueInBytes, long newValueInBytes)
      Update cache size.
      Parameters:
      oldValueInBytes - old amount of bytes that have been used for the sam resource
      newValueInBytes - new amount of bytes that is used by the changed resource
      Returns:
      new cache size;
    • findOrCreate

      public FileCache findOrCreate(URL url) throws IOException
      Find or create file cache.
      Parameters:
      url - URL file path
      Returns:
      file cache
      Throws:
      IOException - if file cache cannot be created or found
    • findOrCreate

      public FileCache findOrCreate(URI uri) throws IOException
      Find or create file cache.
      Parameters:
      uri - URI file path
      Returns:
      file cache
      Throws:
      IOException - if file cache cannot be created or found
    • findOrCreate

      public FileCache findOrCreate(String path) throws IOException
      Find or create file cache.
      Parameters:
      path - file path
      Returns:
      file cache
      Throws:
      IOException - if file cache cannot be created or found
    • findOrCreate

      public FileCache findOrCreate(String path, boolean forceCaching) throws IOException
      Find or create file cache.
      Parameters:
      path - file path
      forceCaching - caching is forced when true if max. cache size isn't reached.
      Returns:
      file cache
      Throws:
      IOException - if file cache cannot be created or found
    • findOrCreate

      public FileCache findOrCreate(Path path) throws IOException
      Find or create file cache.
      Parameters:
      path - file path
      Returns:
      file cache
      Throws:
      IOException - if file cache cannot be created or found
    • findOrCreate

      public FileCache findOrCreate(Path path, boolean forceCaching) throws IOException
      Find or create file cache.
      Parameters:
      path - resource path
      forceCaching - caching is forced when true if max. cache size isn't reached.
      Returns:
      file cache
      Throws:
      IOException - if file cache cannot be created or found
    • findOrCreateByResource

      public FileCache findOrCreateByResource(String resourcePath) throws IOException
      Find or create file cache.
      Parameters:
      resourcePath - resource path
      Returns:
      file cache
      Throws:
      IOException - if file cache cannot be created or found
    • contains

      public boolean contains(String path)
      Is the file already in cache?
      Parameters:
      path - file path
      Returns:
      true if so
    • containsResource

      public boolean containsResource(String resourcePath)
      Is the resource (e.g. JAR resource) already in cache?
      Parameters:
      resourcePath - resouce path
      Returns:
      true if so
    • clear

      public void clear()
      Clear cache.
    • getNormalizedPath

      public static String getNormalizedPath(String path)
      Get normalized path.
      Parameters:
      path - path
      Returns:
      normalized path