Class CacheImpl
- java.lang.Object
-
- net.adoptopenjdk.icedteaweb.resources.cache.CacheImpl
-
class CacheImpl extends java.lang.ObjectThis class helps maintain the ordering of most recently use cache items across multiple jvm instances. The LRU information is stored as a properties file in the root of the file cache directory.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classCacheImpl.CacheHolder
-
Field Summary
Fields Modifier and Type Field Description private CacheIndexHoldercacheIndexprivate static LoggerLOGprivate InfrastructureFileDescriptorrootCacheDir
-
Constructor Summary
Constructors Modifier Constructor Description privateCacheImpl(InfrastructureFileDescriptor recentlyUsed, InfrastructureFileDescriptor cacheDir)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) java.io.FileaddToCache(DownloadInfo info, java.io.InputStream inputStream)private java.io.FilecacheDirFromEntryId(java.lang.String entryId)private booleancannotClearCache()(package private) voidcleanCache()This will remove all old cache items.(package private) booleanclearCache()Clears the cache by deleting all the Netx cache filesprivate java.util.Set<java.lang.String>collectAllEntryIdsFromFileSystem(java.io.File[] levelOneDirs)private CacheIndexEntrycreateCacheEntry(CacheIndex idx, CacheKey key)private java.util.function.Function<CacheIndexEntry,java.lang.String>createExtractor(CacheIdInfo.CacheIdType idType)private voidcreateInfoFile(java.io.File dir)private CacheFileInfoImplcreatePaneObjectArray(CacheIndexEntry entry)private voiddeleteAll(java.io.File... files)private voiddeleteAll(java.util.Collection<java.io.File> files)private voiddeleteDir(java.io.File file)private voiddeleteFilesFromCache(CacheIndexEntry entry)(package private) voiddeleteFromCache(java.net.URL resourceHref, VersionString version)(package private) voiddeleteFromCache(CacheIdInfo cacheId)(package private) voiddeleteFromCache(CacheKey key)private java.lang.StringentryIdFromCacheDir(java.io.File dir)private java.lang.StringextractFileNameFromUrl(java.net.URL resourceHref)(package private) java.util.List<CacheIndexEntry>getAllEntriesInCache(java.net.URL resourceHref)Return all valid cache entries with this URL, regardless of whether they have a version or not.(package private) java.util.Optional<CacheIndexEntry>getBestMatchingEntryInCache(java.net.URL resourceHref, VersionString version)private CacheIndexEntrygetCacheEntry(CacheIndex idx, CacheKey key)private java.io.FilegetCacheFile(CacheIndexEntry entry)(package private) java.io.FilegetCacheFile(CacheKey key)private java.lang.StringgetCacheFileName(java.net.URL resourceHref)(package private) java.util.List<CacheIdInfo>getCacheIds(java.lang.String filter, boolean includeJnlpPath, boolean includeDomain)private CachedFilegetInfoFile(CacheIndexEntry entry)(package private) static CacheImplgetInstance()private longgetMaxSizeInBytes()(package private) java.util.Optional<CachedFile>getResourceInfo(CacheKey key)(package private) voidinvalidateExistingCacheFile(CacheKey key)(package private) booleanisCached(CacheKey key)Returns whether there is a version of the URL contents in the cache.(package private) booleanisUpToDate(CacheKey key, long lastModified)Returns whether there is a version of the URL contents in the cache and it is up to date.private java.io.FilemakeNewCacheDir()private booleanokToClearCache()Returns a boolean indicating if it ok to clear the netx application cache at this point
-
-
-
Field Detail
-
LOG
private static final Logger LOG
-
cacheIndex
private final CacheIndexHolder cacheIndex
-
rootCacheDir
private final InfrastructureFileDescriptor rootCacheDir
-
-
Constructor Detail
-
CacheImpl
private CacheImpl(InfrastructureFileDescriptor recentlyUsed, InfrastructureFileDescriptor cacheDir)
- Parameters:
recentlyUsed- file to be used as recently_used filecacheDir- dir with cache
-
-
Method Detail
-
getInstance
static CacheImpl getInstance()
-
getCacheFile
java.io.File getCacheFile(CacheKey key)
-
getCacheEntry
private CacheIndexEntry getCacheEntry(CacheIndex idx, CacheKey key)
-
addToCache
java.io.File addToCache(DownloadInfo info, java.io.InputStream inputStream) throws java.io.IOException
- Throws:
java.io.IOException
-
createCacheEntry
private CacheIndexEntry createCacheEntry(CacheIndex idx, CacheKey key)
-
makeNewCacheDir
private java.io.File makeNewCacheDir()
-
createInfoFile
private void createInfoFile(java.io.File dir)
-
getResourceInfo
java.util.Optional<CachedFile> getResourceInfo(CacheKey key)
-
isCached
boolean isCached(CacheKey key)
Returns whether there is a version of the URL contents in the cache.- Parameters:
key- the key of the cache entry- Returns:
- whether the cache contains the version
- Throws:
java.lang.IllegalArgumentException- if the resourceHref is not cacheable
-
isUpToDate
boolean isUpToDate(CacheKey key, long lastModified)
Returns whether there is a version of the URL contents in the cache and it is up to date.- Parameters:
key- the key of the cache entrylastModified- time in millis since epoch of last modification- Returns:
- whether the cache contains the version
- Throws:
java.lang.IllegalArgumentException- if the resourceHref is not cacheable
-
getBestMatchingEntryInCache
java.util.Optional<CacheIndexEntry> getBestMatchingEntryInCache(java.net.URL resourceHref, VersionString version)
-
getAllEntriesInCache
java.util.List<CacheIndexEntry> getAllEntriesInCache(java.net.URL resourceHref)
Return all valid cache entries with this URL, regardless of whether they have a version or not. They are not sorted.- Parameters:
resourceHref-- Returns:
-
getCacheIds
java.util.List<CacheIdInfo> getCacheIds(java.lang.String filter, boolean includeJnlpPath, boolean includeDomain)
-
createPaneObjectArray
private CacheFileInfoImpl createPaneObjectArray(CacheIndexEntry entry)
-
invalidateExistingCacheFile
void invalidateExistingCacheFile(CacheKey key)
-
deleteFromCache
void deleteFromCache(CacheKey key)
-
deleteFromCache
void deleteFromCache(java.net.URL resourceHref, VersionString version)
-
deleteFromCache
void deleteFromCache(CacheIdInfo cacheId)
-
createExtractor
private java.util.function.Function<CacheIndexEntry,java.lang.String> createExtractor(CacheIdInfo.CacheIdType idType)
-
deleteFilesFromCache
private void deleteFilesFromCache(CacheIndexEntry entry)
-
clearCache
boolean clearCache()
Clears the cache by deleting all the Netx cache filesNote: Because of how our caching system works, deleting jars of another javaws process is using them can be quite disastrous. Hence why Launcher creates lock files and we check for those by calling
okToClearCache()- Returns:
- true if the cache could be cleared and was cleared
-
deleteAll
private void deleteAll(java.util.Collection<java.io.File> files)
-
deleteAll
private void deleteAll(java.io.File... files)
-
deleteDir
private void deleteDir(java.io.File file)
-
cleanCache
void cleanCache()
This will remove all old cache items.
-
collectAllEntryIdsFromFileSystem
private java.util.Set<java.lang.String> collectAllEntryIdsFromFileSystem(java.io.File[] levelOneDirs)
-
getMaxSizeInBytes
private long getMaxSizeInBytes()
-
getCacheFile
private java.io.File getCacheFile(CacheIndexEntry entry)
-
getInfoFile
private CachedFile getInfoFile(CacheIndexEntry entry)
-
entryIdFromCacheDir
private java.lang.String entryIdFromCacheDir(java.io.File dir)
-
cacheDirFromEntryId
private java.io.File cacheDirFromEntryId(java.lang.String entryId)
-
getCacheFileName
private java.lang.String getCacheFileName(java.net.URL resourceHref)
-
extractFileNameFromUrl
private java.lang.String extractFileNameFromUrl(java.net.URL resourceHref)
-
cannotClearCache
private boolean cannotClearCache()
-
okToClearCache
private boolean okToClearCache()
Returns a boolean indicating if it ok to clear the netx application cache at this point- Returns:
- true if the cache can be cleared at this time without problems
-
-