> On Oct 25, 2016, at 3:30 PM, Hugi Thordarson <[email protected]> wrote:
>
> Hi all.
> I’m working on a project where external applications modify the DB, so I have
> to disable caching (or probably better, make it valid for only a very short
> period of time) for all entities in a certain DataMap. What’s the easiest way
> for me to achieve this?
>
> Cheers,
> - hugi
Hi Hugi,
I recommend using EhCacheQueryCache and configuring expiration policies in
ehcache.xml . This is all about *query* cache of course. But with proper query
cache, object cache is refreshed as a side effect of query execution. You can
install EhCacheQueryCache via Cayenne DI.
A second option is even better ... if you are using Bootique. The upcoming
Bootique 0.21 integrates newer EhCache 3.x and provides both API and XML-based
EhCache configs. Still need to document this, but in short, you drop
bootique-cayenne-ehcache [1] in your app, and you already have EhCache with
default settings working. Here is an API-config example:
Configuration<String, List> c = new MutableConfiguration<String, List>()
.setTypes(String.class, List.class)
.setExpiryPolicyFactory(...);
EhCacheModule.contributeConfiguration(binder).addBinding("somecayennecachegroup").toInstance(c);
Andrus
[1]
https://github.com/bootique/bootique-cayenne/tree/master/bootique-cayenne-ehcache