Package net.jalbum.util
Class DiskCache
java.lang.Object
net.jalbum.util.DiskCache
Manage the caching of remotely fetched URLs in a local directory (the primary
cache dir) Also synchronizes a target cache dir with the local cache dir.
No longer cached files are deleted from the primary cache dir and target
cache dir
- Since:
- 29
-
Nested Class Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionAdd a file to be loaded into the cache.Add a file to be loaded into the cache.The actual loading is performed by refresh()Add a file to be loaded into the cache.Add a file to be loaded into the cache.Add a file to be loaded into the cache.The actual loading is performed by refresh()void
clear()
Clear list of files to be addedvoid
onError
(Consumer<DiskCache.DCException> errorHandler) void
refresh()
Load files that have been added by the add() calls into the primary cache dir.Older files present in local cache that aren't added are deleted from primary local cache.void
refresh
(boolean abortOnError) Like refresh(), but will throw an OperationAbortedException on errorint
size()
void
Synchronize targetDir with primary cache dir (Copy updated files and delete stale files)
-
Constructor Details
-
DiskCache
- Parameters:
primaryCacheDir
- - Local directory to store cached files in Uses ".diskcache.json" file to store local database of managed files Only managed files are copied and deleted
-
DiskCache
- Parameters:
primaryCacheDir
- - Local directory to store cached files indbName
- - Name of database file that keeps track of managed files (json format). Only managed files are copied and deleted
-
-
Method Details
-
onError
-
add
Add a file to be loaded into the cache. The actual loading is performed by refresh()- Parameters:
url
- URL of file as a String- Returns:
- this DiskCache object (for chaining add calls)
-
add
Add a file to be loaded into the cache. The actual loading is performed by refresh()- Parameters:
url
- URL of file as a URL object- Returns:
- this DiskCache object (for chaining add calls)
-
add
Add a file to be loaded into the cache.The actual loading is performed by refresh()- Parameters:
url
- URL of file as a URL objectlocalName
- Alternative local name to use- Returns:
- this DiskCache object (for chaining add calls)
-
add
Add a file to be loaded into the cache. The actual loading is performed by refresh()- Parameters:
file
- File to add- Returns:
- this DiskCache object (for chaining add calls)
-
add
Add a file to be loaded into the cache.The actual loading is performed by refresh()- Parameters:
file
- File to addlocalName
- Alternative local name to use- Returns:
- this DiskCache object (for chaining add calls)
-
size
public int size()- Returns:
- Number of added files
-
clear
public void clear()Clear list of files to be added -
refresh
Load files that have been added by the add() calls into the primary cache dir.Older files present in local cache that aren't added are deleted from primary local cache. Files are only loaded if missing from local cache or in need of update. Files are loaded simultaneously in order to speed up loading.- Throws:
DiskCache.DCException
- In case a file couldn't be loaded that was also missing in the local cache
-
refresh
Like refresh(), but will throw an OperationAbortedException on error- Parameters:
abortOnError
- set to true in order to abort on error- Throws:
DiskCache.DCException
- In case a file couldn't be loaded that was also missing in the local cacheOperationAbortedException
-
getLastException
- Returns:
- Last DCException from refresh() call or null if no error occurred.
-
getContents
- Returns:
- contents of primary cache dir
-
syncTo
Synchronize targetDir with primary cache dir (Copy updated files and delete stale files)- Parameters:
targetDir
-- Throws:
IOException
-