Thymeleaf StandardCache : Enabling or not

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view

Thymeleaf StandardCache : Enabling or not
This post was updated on .

Im using thymleaf 3.0.8 with spring-mvc 4.3.7.
Im trying to optimize my application. We have multiple pages (25) including many fragments (around 100).
I just find out the default values for the template and expression cache but Im not sure to understand the expression cache exactly.

I increase the expression cache maximum capacity to 5000. When I enable the trace, i see around 4000 items in the expressions cache. My pages are quite big but this seems quite a lot.

Also, it looks that the cache get bigger and bigger. While navigating on the same page, my expression cache keep increasing.

I see labels that are put back in the cache when I got back on a page.

] - [THYMELEAF][http-bio-8080-exec-8][EXPRESSION_CACHE][CACHE_ADD][3980] Adding cache entry in cache "EXPRESSION_CACHE" for key "expr|#{lbl.button.billing.billing.schedule}". New size is 3980.
] - [THYMELEAF][http-bio-8080-exec-4][EXPRESSION_CACHE][CACHE_ADD][3994] Adding cache entry in cache "EXPRESSION_CACHE" for key "fsig|AmountFrag(fieldStr, fieldId)". New size is 3994.
] - [THYMELEAF][http-bio-8080-exec-4][EXPRESSION_CACHE][CACHE_ADD][4005] Adding cache entry in cache "EXPRESSION_CACHE" for key "expr|*{paymentReceived}". New size is 4005.

This is my configuration for now :

        @Bean(name = "templateEngine")
        public SpringTemplateEngine getTemplateEngine() {
                final SpringTemplateEngine templateEngine = new SpringTemplateEngine();

                StandardCacheManager cacheManager = new StandardCacheManager();
                return templateEngine;

Is it possible to have explanation about the expression cache ? What does it cache exactly. The value of the expression or something else ? Any suggestion about the configuration of the cache for better performance ?

Reply | Threaded
Open this post in threaded view

Re: Understanding expression cache
This post was updated on .
Im wondering if the expression cache and the template cache should be activated in a production environment.

In our performance test, when we put a lot of load on our application (650 users, loadbalancing on 6 jboss eap6, java 8) we see some huge delay in the thymeleaf cache (putWithoutTracing).
It looks like the all the threads are block since there a synchronise block on the fifo list.

I did some test locally with the default cache, by turning off both cache (expression and template) and by increasing the cache as well.

Locally, I have better result by increasing the cache (around 20% faster) but there's not a huge difference when I turn off the cache (*average 36ms difference).

So im wondering if the cache is really needed. In a "load" environnement, disabling the cache could  avoid blocking thread.

* I used the thymeleaf template processing log  to compare :
Ex:  [THYMELEAF][http-bio-8080-exec-9][search_results][en][149885355][150] TEMPLATE "search_results" WITH LOCALE en PROCESSED IN 149885355 nanoseconds (approx. 150ms)

Is my "reasoning" rigth?