Reputation: 2841
Jetty caches by default static resources like property files for performance reasons. For instance, some code like this:
public class FrontServlet extends HttpServlet
{
private final Properties routes = new Properties();
@Override
public void init()
throws ServletException
{
try {
this.routes.load(this.getClass().getClassLoader().getResourceAsStream("routes.properties"));
} catch (IOException | NullPointerException e) {
throw new ServletException(e);
}
}
}
would continue working even after I delete the routes.properties
file, because it would still be available from the cache, rather than from the disk. The Eclipse Jetty plugin documentation also mentions this: look for "Disable Server Cache".
Now, I'd like to disable this feature in development environments to avoid false positives. The Jetty documentation mentions that there is a init parameter called maxCacheSize
that, if set to 0
, disables the cache. However, I tried it both as a context parameter:
<context-param>
<param-name>org.eclipse.jetty.servlet.maxCacheSize</param-name>
<param-value>0</param-value>
</context-param>
and as a servlet init parameter:
<servlet>
...
<init-param>
<param-name>org.eclipse.jetty.servlet.maxCacheSize</param-name>
<param-value>0</param-value>
</init-param>
</servlet>
to no avail.
Does anyone know how to do this?
EDIT:
The routes.properties
file is still found even after I restart the Web server, and the Vagrant virtual machine it's running on. I should also mention that I'm using the Maven Jetty plugin, thus launching the server with mvn jetty:run
.
Upvotes: 3
Views: 3507
Reputation: 49515
This is unrelated to a server cache.
The routes.properties
is loaded once, during Servlet Context Initialization, and used from then on out.
Only a destroy of the running context (ie: restart the web server) will cause it to call FrontServlet.init()
again.
Upvotes: 1