# Class CachedResource

java.lang.Object
org.apache.catalina.webresources.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 Summary

Constructors
Constructor
Description
`CachedResource(Cache cache, StandardRoot root, String path, long ttl, int objectMaxSizeBytes, boolean usesClassLoaderResources)`

## Method Summary

Modifier and Type
Method
Description
`boolean`
`canRead()`
Checks if this resource can be read.
`boolean`
`delete()`
Deletes this resource.
`boolean`
`exists()`
Checks if this resource exists.
`String`
`getCanonicalPath()`
Returns the canonical path of this resource.
`Certificate[]`
`getCertificates()`
Returns the certificates that were used to sign this resource to verify it.
`URL`
`getCodeBase()`
`byte[]`
`getContent()`
Returns the binary content of this resource.
`long`
`getContentLength()`
Returns the content length of this resource.
`long`
`getCreation()`
Returns the creation time of this resource.
`String`
`getETag()`
Returns the weak ETag calculated from the content length and last modified.
`InputStream`
`getInputStream()`
Obtains an InputStream based on the contents of this resource.
`long`
`getLastModified()`
Returns the last modified time.
`String`
`getLastModifiedHttp()`
Returns the last modified time in HTTP format.
`Manifest`
`getManifest()`
Returns the manifest associated with this resource.
`String`
`getMimeType()`
Returns the MIME type for this Resource.
`String`
`getName()`
Returns the name of this resource.
`protected long`
`getNextCheck()`
`String`
`getStrongETag()`
Return the strong ETag if available else return the weak ETag calculated from the content length and last modified.
`URL`
`getURL()`
Returns a URL to access this resource.
`String`
`getWebappPath()`
Returns the webapp path of this resource.
`WebResourceRoot`
`getWebResourceRoot()`
Returns a reference to the WebResourceRoot of which this WebResource is a part.
`boolean`
`isDirectory()`
Checks if this resource is a directory.
`boolean`
`isFile()`
Checks if this resource is a file.
`boolean`
`isVirtual()`
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`.
`void`
`setMimeType(String mimeType)`
Set the MIME type for this Resource.
`protected boolean`
`validateResource(boolean useClassLoaderResources)`
`protected boolean`
`validateResources(boolean useClassLoaderResources)`

### Methods inherited from class Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### CachedResource

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

## Method Details

### validateResource

protected boolean validateResource(boolean useClassLoaderResources)

### validateResources

protected boolean validateResources(boolean useClassLoaderResources)

### getNextCheck

protected long getNextCheck()

### getLastModified

public long getLastModified()
Description copied from interface: `WebResource`
Returns the last modified time.

Specified by:
  `getLastModified` in interface `WebResource`
Returns:
  `File.lastModified()`.

### getLastModifiedHttp

public String getLastModifiedHttp()
Description copied from interface: `WebResource`
Returns the last modified time in HTTP format.

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.

### exists

public boolean exists()
Description copied from interface: `WebResource`
Checks if this resource exists.

Specified by:
  `exists` in interface `WebResource`
Returns:
  `File.exists()`.

### 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

### isDirectory

public boolean isDirectory()
Description copied from interface: `WebResource`
Checks if this resource is a directory.

Specified by:
  `isDirectory` in interface `WebResource`
Returns:
  `File.isDirectory()`.

### isFile

public boolean isFile()
Description copied from interface: `WebResource`
Checks if this resource is a file.

Specified by:
  `isFile` in interface `WebResource`
Returns:
  `File.isFile()`.

### delete

public boolean delete()
Description copied from interface: `WebResource`
Deletes this resource.

Specified by:
  `delete` in interface `WebResource`
Returns:
  `File.delete()`.

### getName

public String getName()
Description copied from interface: `WebResource`
Returns the name of this resource.

Specified by:
  `getName` in interface `WebResource`
Returns:
  `File.getName()`.

### getContentLength

public long getContentLength()
Description copied from interface: `WebResource`
Returns the content length of this resource.

Specified by:
  `getContentLength` in interface `WebResource`
Returns:
  `File.length()`.

### getCanonicalPath

public String getCanonicalPath()
Description copied from interface: `WebResource`
Returns the canonical path of this resource.

Specified by:
  `getCanonicalPath` in interface `WebResource`
Returns:
  `File.getCanonicalPath()`.

### canRead

public boolean canRead()
Description copied from interface: `WebResource`
Checks if this resource can be read.

Specified by:
  `canRead` in interface `WebResource`
Returns:
  `File.canRead()`.

### getWebappPath

public String getWebappPath()
Description copied from interface: `WebResource`
Returns the webapp path of this resource.

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`
Returns the weak ETag calculated from the content length and last modified.

Specified by:
  `getETag` in interface `WebResource`
Returns:
  The ETag for this resource

### getStrongETag

public String getStrongETag()
Description copied from interface: `WebResource`
Return the strong ETag if available else return the weak ETag calculated from the content length and last modified.

Specified by:
  `getStrongETag` 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

### getMimeType

public String getMimeType()
Description copied from interface: `WebResource`
Returns the MIME type for this Resource.

Specified by:
  `getMimeType` in interface `WebResource`
Returns:
  the MIME type for this Resource.

### getInputStream

public InputStream getInputStream()
Description copied from interface: `WebResource`
Obtains 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()
Description copied from interface: `WebResource`
Returns the binary content of this resource.

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.

### getCreation

public long getCreation()
Description copied from interface: `WebResource`
Returns the creation time of this resource.

Specified by:
  `getCreation` in interface `WebResource`
Returns:
  The time the file was created. If not available, the result of `WebResource.getLastModified()` will be returned.

### getURL

public URL getURL()
Description copied from interface: `WebResource`
Returns a URL to access this resource.

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.

### getCertificates

public Certificate[] getCertificates()
Description copied from interface: `WebResource`
Returns the certificates that were used to sign this resource to verify it.

Specified by:
  `getCertificates` in interface `WebResource`
Returns:
  the certificates that were used to sign this resource to verify it or @null if none.
See Also:
  - `JarEntry.getCertificates()`

### getManifest

public Manifest getManifest()
Description copied from interface: `WebResource`
Returns the manifest associated with this resource.

Specified by:
  `getManifest` in interface `WebResource`
Returns:
  the manifest associated with this resource or @null if none.
See Also:
  - `JarFile.getManifest()`

### getWebResourceRoot

public WebResourceRoot getWebResourceRoot()
Description copied from interface: `WebResource`
Returns a reference to the WebResourceRoot of which this WebResource is a part.

Specified by:
  `getWebResourceRoot` in interface `WebResource`
Returns:
  a reference to the WebResourceRoot of which this WebResource is a part.