Package ch.autumo.beetroot.cache
Class FileCacheManager
java.lang.Object
ch.autumo.beetroot.cache.FileCacheManager
File cache manager.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final org.slf4j.Loggerstatic final long -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clear cache.booleanIs the file already in cache?booleancontainsResource(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 forcedCaching) Find or create file cache.findOrCreateByResource(String resourcePath) Find or create file cache.static FileCacheManagerFile cache manager.longGet maximum size of this cache.static StringgetNormalizedPath(String path) Get normalized path.longgetSize()Get size of cache.booleanhasSpace(long oldValueInBytes, long newValueInBytes) Is there space left in the cache?longupdateCacheSize(long oldValueInBytes, long newValueInBytes) Update cache size.
-
Field Details
-
LOG
protected static final org.slf4j.Logger LOG -
MAX_CACHE_SIZE
public static final long MAX_CACHE_SIZE
-
-
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 same 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 same 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- IO exception
-
findOrCreate
Find or create file cache.- Parameters:
uri- URI file path- Returns:
- file cache
- Throws:
IOException- IO exception
-
findOrCreate
Find or create file cache.- Parameters:
path- file path- Returns:
- file cache
- Throws:
IOException- IO exception
-
findOrCreate
Find or create file cache.- Parameters:
path- file pathforceCaching- caching is forced when true if max. cache size isn't reached; force caching breaks the file size limit, but not the cache size limit!- Returns:
- file cache
- Throws:
IOException- IO exception
-
findOrCreate
Find or create file cache.- Parameters:
path- file path- Returns:
- file cache
- Throws:
IOException- IO exception
-
findOrCreate
Find or create file cache.- Parameters:
path- resource pathforcedCaching- caching is forced when true if max. cache size isn't reached; force caching breaks the file size limit, but not the cache size limit!- Returns:
- file cache
- Throws:
IOException- IO exception
-
findOrCreateByResource
Find or create file cache.- Parameters:
resourcePath- resource path- Returns:
- file cache
- Throws:
IOException- IO exception
-
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- resource path- Returns:
- true if so
-
clear
public void clear()Clear cache. -
getMaxSize
public long getMaxSize()Get maximum size of this cache.- Returns:
- max. size
-
getNormalizedPath
Get normalized path.- Parameters:
path- path- Returns:
- normalized path
-