0

Could anyone give me more details about the "cacheTtl" used in the Tomcat static cache? I see in the documentation it's mentioned

The amount of time in milliseconds between the revalidation of cache entries. If not specified, the default value is 5000 (5 seconds).

What does "revalidation of cache entries" mean exactly? and would this affect the performance of my application if I have too many cached resources?

Thanks in advance!

Piotr P. Karwasz
  • 12,857
  • 3
  • 20
  • 43

1 Answers1

2

"Revalidating" simply means reading from the disk again. Therefore if a client requests a static resource:

  • if the resource was read less than cacheTtl seconds ago, the data cached in Java's heap memory will be returned,
  • if the resource was read more than cacheTtl seconds ago, Tomcat will read the data from disk again (and cache it).

Since memory access is an order of magnitude faster than disk access (cf. this question), if the cache is not full, a longer TTL means better performance. When the cache becomes full (above 90% capacity), Tomcat can evict cache entries before they reach their TTL.

The real performance impact of Tomcat caching is however much more complex because:

  • modern operating systems cache open files themselves (using the RAM not used by applications), therefore a "disk read" might actually be almost as fast as a "heap memory read". Decreasing Tomcat's memory might sometimes improve performance,
  • modern operating systems have a sendfile system call: if you want to return a file to the client as-is, the OS can do it for you (much faster than Java code). Tomcat's DefaultServlet by default uses sendfile (cf. documentation) for files larger than 48 KiB. There is no need to cache files larger than that.
Piotr P. Karwasz
  • 12,857
  • 3
  • 20
  • 43