Class CacheImpl


  • class CacheImpl
    extends java.lang.Object
    This 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.
    • Method Detail

      • getInstance

        static CacheImpl getInstance()
      • getCacheFile

        java.io.File getCacheFile​(CacheKey key)
      • addToCache

        java.io.File addToCache​(DownloadInfo info,
                                java.io.InputStream inputStream)
                         throws java.io.IOException
        Throws:
        java.io.IOException
      • makeNewCacheDir

        private java.io.File makeNewCacheDir()
      • createInfoFile

        private void createInfoFile​(java.io.File dir)
      • 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 entry
        lastModified - 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)
      • invalidateExistingCacheFile

        void invalidateExistingCacheFile​(CacheKey key)
      • deleteFromCache

        void deleteFromCache​(CacheKey key)
      • deleteFromCache

        void deleteFromCache​(java.net.URL resourceHref,
                             VersionString version)
      • deleteFromCache

        void deleteFromCache​(CacheIdInfo cacheId)
      • deleteFilesFromCache

        private void deleteFilesFromCache​(CacheIndexEntry entry)
      • clearCache

        boolean clearCache()
        Clears the cache by deleting all the Netx cache files

        Note: 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)
      • 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