Package ch.autumo.commons.cache
Class FileCacheManager
java.lang.Object
ch.autumo.commons.cache.FileCacheManager
File cache manager.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final org.slf4j.Logger
Logger.static final long
Max file cache size in bytes. -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Clear cache.boolean
Is the file already in cache?boolean
containsResource
(String resourcePath) Is the resource (e.g.findOrCreate
(String path) Find or create file cache.findOrCreate
(String path, boolean forceCaching) Find or create file cache.findOrCreate
(URI uri) Find or create file cache.findOrCreate
(URL url) Find or create file cache.findOrCreate
(Path path) Find or create file cache.findOrCreate
(Path path, boolean forceCaching) Find or create file cache.findOrCreateByResource
(String resourcePath) Find or create file cache.static FileCacheManager
File cache manager.static String
getNormalizedPath
(String path) Get normalized path.long
getSize()
Get size of cache.boolean
hasSpace
(long oldValueInBytes, long newValueInBytes) Is there space left in the cache?long
updateCacheSize
(long oldValueInBytes, long newValueInBytes) Update cache size.
-
Field Details
-
LOG
protected static final org.slf4j.Logger LOGLogger. -
MAX_CACHE_SIZE
public static final long MAX_CACHE_SIZEMax file cache size in bytes.
-
-
Method Details
-
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 resourcenewValueInBytes
- 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 resourcenewValueInBytes
- new amount of bytes that is used by the changed resource- Returns:
- new cache size;
-
findOrCreate
Find or create file cache.- Parameters:
url
- URL file path- Returns:
- file cache
- Throws:
IOException
- if file cache cannot be created or found
-
findOrCreate
Find or create file cache.- Parameters:
uri
- URI file path- Returns:
- file cache
- Throws:
IOException
- if file cache cannot be created or found
-
findOrCreate
Find or create file cache.- Parameters:
path
- file path- Returns:
- file cache
- Throws:
IOException
- if file cache cannot be created or found
-
findOrCreate
Find or create file cache.- Parameters:
path
- file pathforceCaching
- 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
Find or create file cache.- Parameters:
path
- file path- Returns:
- file cache
- Throws:
IOException
- if file cache cannot be created or found
-
findOrCreate
Find or create file cache.- Parameters:
path
- resource pathforceCaching
- 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
Find or create file cache.- Parameters:
resourcePath
- resource path- Returns:
- file cache
- Throws:
IOException
- if file cache cannot be created or found
-
contains
Is the file already in cache?- Parameters:
path
- file path- Returns:
- true if so
-
containsResource
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
Get normalized path.- Parameters:
path
- path- Returns:
- normalized path
-