Rajat Gupta
Rajat Gupta

Reputation: 26607

Conditionally enable or disable o:cache through an attribute?

I could not find any attribute to conditionally enable or disable o:cache. Is there any other way to accomplish this ?

Something like this:

<o:cache scope="application" disabled="#{someELexprsn}">
    ....
</o:cache>

I would like to disable o:cache based on some condition.

(Actually I use this o:cache on a page that is used to display page for several type of entities but I want to enable cache only for pages of certain entities.)

Upvotes: 2

Views: 81

Answers (1)

BalusC
BalusC

Reputation: 1109262

There's no attribute which enables you to disable the cache on a per-request basis. Feel free to open a feature request in order to get it added to OmniFaces.

In the meanwhile, you could abuse the reset attribute.

<o:cache scope="application" reset="#{someELexprsn}">
    ....
</o:cache>

Under the covers, it will still cache it but it would be resetted everytime the EL expression evaluates true. In effects, it has exactly the desired effect as intented, although it is under the covers done in a clumsy way. That may be sufficient until the new attribute is been added by OmniFaces guys. The disabled attribute would instead of a reset perform a full pass-through of rendering (thus, in this particular example, the cached content would be still in application scope, but is simply not been rendered).

Upvotes: 2

Related Questions