Class CachedResource

  • All Implemented Interfaces:
    WebResource

    public class CachedResource
    extends Object
    implements WebResource
    This class is designed to wrap a 'raw' WebResource and providing caching for expensive operations. Inexpensive operations may be passed through to the underlying resource.
    • Constructor Detail

      • CachedResource

        public CachedResource​(Cache cache,
                              StandardRoot root,
                              String path,
                              long ttl,
                              int objectMaxSizeBytes,
                              boolean usesClassLoaderResources)
    • Method Detail

      • validateResource

        protected boolean validateResource​(boolean useClassLoaderResources)
      • validateResources

        protected boolean validateResources​(boolean useClassLoaderResources)
      • getNextCheck

        protected long getNextCheck()
      • getLastModifiedHttp

        public String getLastModifiedHttp()
        Specified by:
        getLastModifiedHttp in interface WebResource
        Returns:
        the last modified time of this resource in the correct format for the HTTP Last-Modified header as specified by RFC 2616.
      • isVirtual

        public boolean isVirtual()
        Description copied from interface: WebResource
        Indicates if this resource is required for applications to correctly scan the file structure but that does not exist in either the main or any additional WebResourceSet. For example, if an external directory is mapped to /WEB-INF/lib in an otherwise empty web application, /WEB-INF will be represented as a virtual resource.
        Specified by:
        isVirtual in interface WebResource
        Returns:
        true for a virtual resource
      • getWebappPath

        public String getWebappPath()
        Specified by:
        getWebappPath in interface WebResource
        Returns:
        The path of this resource relative to the web application root. If the resource is a directory, the return value will end in '/'.
      • getETag

        public String getETag()
        Description copied from interface: WebResource
        Return the strong ETag if available (currently not supported) else return the weak ETag calculated from the content length and last modified.
        Specified by:
        getETag in interface WebResource
        Returns:
        The ETag for this resource
      • setMimeType

        public void setMimeType​(String mimeType)
        Description copied from interface: WebResource
        Set the MIME type for this Resource.
        Specified by:
        setMimeType in interface WebResource
        Parameters:
        mimeType - The mime type that will be associated with the resource
      • getInputStream

        public InputStream getInputStream()
        Description copied from interface: WebResource
        Obtain an InputStream based on the contents of this resource.
        Specified by:
        getInputStream in interface WebResource
        Returns:
        An InputStream based on the contents of this resource or null if the resource does not exist or does not represent a file
      • getContent

        public byte[] getContent()
        Specified by:
        getContent in interface WebResource
        Returns:
        the binary content of this resource or null if it is not available in a byte[] because, for example, it is too big.
      • getURL

        public URL getURL()
        Specified by:
        getURL in interface WebResource
        Returns:
        a URL to access the resource or null if no such URL is available or if the resource does not exist.
      • getCodeBase

        public URL getCodeBase()
        Specified by:
        getCodeBase in interface WebResource
        Returns:
        the code base for this resource that will be used when looking up the assigned permissions for the code base in the security policy file when running under a security manager.