Tomcat's caching mechanism

  1. HTTP cache: Tomcat supports the HTTP cache mechanism, and the cache policy can be controlled by setting fields such as Cache-Control, Expires, and ETag in the response header. These fields tell the browser whether the response can be cached and the validity period of the cache.

  2. Servlet cache: Tomcat also provides a Servlet cache mechanism, which can cache the response content of the Servlet to avoid repeated generation of the same response. Servlet caching can be enabled by configuring <cacheable>true</cacheable> in the web.xml file.

  3. Session cache: Tomcat supports session (Session) cache, which can store session data in memory to improve session access speed. Session caching can be enabled by configuring <Manager className="org.apache.catalina.session.PersistentManager" /> in the context.xml file.

  4. Static resource caching: Tomcat can cache static resources (such as images, CSS and JavaScript files) to reduce access to the file system. Static resource caching can be enabled by configuring the <Resources> element in the context.xml file.

When I was working on a project, a jsp page was not read out after it was modified. After careful study of tomcat, I found that
when a jsp page is requested, Tomcat will assign it to JspServlet for processing. In the jspServlet method service(), there is a sentence
boolean precompile = preCompile(request); 
it will judge whether you have the ?jsp_precompile query string when you request the jsp page, if you bring it, it will recompile
and then use serviceJspFile(request, response, jspUri, null, precompile) to further judge whether to compile jsp file, the following is the JspServletWraper service method

 if (options.getDevelopment() || firstTime ) { 
 synchronized (this) { 
 if (firstTime) { 
firstTime = false; 
} 
// The following sets reload to true, if necessary 
ctxt.compile(); 
} 
} 

The key lies in the judgment of Compiler's isOutDated(boolean checkClass).
The judging criterion is that if the last modification time of the jsp is greater than the last modification time of the target file, it needs to be recompiled. Another situation is that even if the last modification time of the jsp is later than the last modification time of the target file, as long as the last modification
time of a file included in the include command in the jsp is earlier than the modification time of the corresponding target file, it also needs to be rewritten. Compile the main jsp file's

Guess you like

Origin blog.csdn.net/oligaga/article/details/132677864