How do I disable template caching?

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

How do I disable template caching?

TLLinux
I'm using TL 3.02 with the Layout dialect. This is on a site that's an upgrade from (originally) TL 1.x versions. It's also using Spring 4.

Everything is working quite nicely, except it is caching templates, which means that I need to re-deploy (and re-create objects in the database) every time I want to make a change to a template file. Obviously, that is so painfully slow, it makes me wish I'm using PHP.

I read all the instructions about disabling caching, and none of it works. I've tried this:

    <bean id="templateResolver"
          class="org.thymeleaf.spring4.templateresolver.SpringResourceTemplateResolver">
        <property name="prefix" value="/WEB-INF/templates/" />
        <property name="suffix" value=".html" />
        <property name="templateMode" value="HTML" />
        <property name="cacheable" value="false"/>
        <property name="cacheTTLMs" value="1"/>
    </bean>  

and it doesn't change anything. I would think that just setting cacheable to false would do it, but it did not, so I tried setting the TTL to 1, and that did not help. I then tried this:

    <bean id="templateEngine"
          class="org.thymeleaf.spring4.SpringTemplateEngine">
        <property name="templateResolver" ref="templateResolver" />
        <property name="enableSpringELCompiler" value="true"/>
        <property name="cacheManager"><null/></property>
        <property name="additionalDialects">
            <set>
                <bean class="nz.net.ultraq.thymeleaf.LayoutDialect"/>
            </set>
        </property>
    </bean>

setting the cacheManager to null, and that didn't help.

I assume I'm not the only one who needs to turn off caching right? Thanks
Reply | Threaded
Open this post in threaded view
|

Re: How do I disable template caching?

TLLinux
I found a solution. In one of my controllers, which gets used basically every time the app is used, I did:

    @Autowired
    private ITemplateResolver templateResolver;

And then in a method that gets called basically any time the app is used, I put:

final ServletContextTemplateResolver sctr = (ServletContextTemplateResolver) templateResolver;
sctr.setCacheable(false);

I think this is a very clunky and ridiculous solution, but that is the only way that turns caching off. Should I file a bug on this?
Reply | Threaded
Open this post in threaded view
|

Re: How do I disable template caching?

as87321234
In reply to this post by TLLinux
This works for me

        <bean id="templateResolver"
                class="org.thymeleaf.templateresolver.ServletContextTemplateResolver">
                <property name="prefix" value="/WEB-INF/views/" />
                <property name="suffix" value=".html" />
                <property name="templateMode" value="HTML5" />
        <property name="cacheable" value="false" />
        </bean>