Package org.spdx.utility
Class DownloadCache
java.lang.Object
org.spdx.utility.DownloadCache
This singleton class provides a flexible download cache for the rest of the library. If enabled, URLs that are
requested using this class will have their content automatically cached locally on disk (in a directory that adheres
to the XDG Base Directory Specification - https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html),
and any subsequent requests will be served out of that cache. Cache entries will also be automatically checked every
so often for staleness using HTTP ETag requests (which are more efficient than full HTTP requests). The interval
between such checks is configurable (and can even be turned off, which makes every download request re-check the URL
for staleness).
The cache is configured via these Configuration options:
* org.spdx.storage.listedlicense.enableCache:
Controls whether the cache is enabled or not. Defaults to false i.e. the cache is disabled.
* org.spdx.storage.listedlicense.cacheCheckIntervalSecs:
How many seconds should the cache wait between issuing ETag requests to determine whether cached content is
stale? Defaults to 86,400 seconds (24 hours).
-
Method Summary
Modifier and TypeMethodDescriptionstatic DownloadCachegetUrlInputStream(URL url) getUrlInputStream(URL url, boolean restrictRedirects) voidResets (deletes) the local cache.
-
Method Details
-
getInstance
- Returns:
- The singleton instance of the DownloadCache class.
-
resetCache
Resets (deletes) the local cache.- Throws:
IOException
-
getUrlInputStream
- Parameters:
url- The URL to get an input stream for. Note that redirects issued by this url are restricted to known SPDX hosts. Redirects to other hosts will cause an IOException to be thrown.- Returns:
- An InputStream for url, or null if url is null. Note that this InputStream may be of different concrete types, depending on whether the content is being served out of cache or not.
- Throws:
IOException- When an IO error of some kind occurs.
-
getUrlInputStream
- Parameters:
url- The URL to get an input stream for.restrictRedirects- A flag that controls whether redirects returned by url are restricted to known SPDX hosts or not. Defaults to true. USE EXTREME CAUTION WHEN TURNING THIS OFF!- Returns:
- An InputStream for url, or null if url is null. Note that this InputStream may be of different concrete types, depending on whether the content is being served out of cache or not.
- Throws:
IOException- When an IO error of some kind occurs.
-