MCPcopy Index your code
hub / github.com/apache/tomcat / CachedResource

Class CachedResource

java/org/apache/catalina/webresources/CachedResource.java:51–701  ·  view source on GitHub ↗

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.

Source from the content-addressed store, hash-verified

49 * operations may be passed through to the underlying resource.
50 */
51public class CachedResource implements WebResource {
52
53 private static final Log log = LogFactory.getLog(CachedResource.class);
54 private static final StringManager sm = StringManager.getManager(CachedResource.class);
55
56 // Estimate (on high side to be safe) of average size excluding content
57 // based on profiler data.
58 private static final long CACHE_ENTRY_SIZE = 500;
59
60 private final Cache cache;
61 private final StandardRoot root;
62 private final String webAppPath;
63 private final long ttl;
64 private final int objectMaxSizeBytes;
65 private final boolean usesClassLoaderResources;
66
67 private volatile WebResource webResource;
68 private volatile WebResource[] webResources;
69 private volatile long nextCheck;
70
71 private volatile Long cachedLastModified = null;
72 private volatile String cachedLastModifiedHttp = null;
73 private volatile byte[] cachedContent = null;
74 private volatile Boolean cachedIsFile = null;
75 private volatile Boolean cachedIsDirectory = null;
76 private volatile Boolean cachedExists = null;
77 private volatile Boolean cachedIsVirtual = null;
78 private volatile Long cachedContentLength = null;
79 private volatile String cachedStrongETag = null;
80
81
82 /**
83 * Construct a cached resource.
84 *
85 * @param cache The cache
86 * @param root The standard root
87 * @param path The web application path
88 * @param ttl The time to live in milliseconds
89 * @param objectMaxSizeBytes The maximum size of objects to cache
90 * @param usesClassLoaderResources Whether class loader resources are used
91 */
92 public CachedResource(Cache cache, StandardRoot root, String path, long ttl, int objectMaxSizeBytes,
93 boolean usesClassLoaderResources) {
94 this.cache = cache;
95 this.root = root;
96 this.webAppPath = path;
97 this.ttl = ttl;
98 nextCheck = ttl + System.currentTimeMillis();
99 this.objectMaxSizeBytes = objectMaxSizeBytes;
100 this.usesClassLoaderResources = usesClassLoaderResources;
101 }
102
103 /**
104 * Validates the cached resource.
105 *
106 * @param useClassLoaderResources Whether class loader resources are used
107 *
108 * @return <code>true</code> if the cached resource is still valid

Callers

nothing calls this directly

Calls 2

getLogMethod · 0.95
getManagerMethod · 0.95

Tested by

no test coverage detected