You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Hugi Thordarson <hu...@karlmenn.is> on 2016/10/25 12:30:18 UTC

Disabling caching for all entities in a certain DataMap

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

Re: Disabling caching for all entities in a certain DataMap

Posted by Andrew Willerding <aw...@itsurcom.com>.
I am experiencing this situation the for the first time where the 
database is modified outside of my cayenne based application. 
Unfortunately the explanation below means absolutely nothing to me.  
;-)  Neither my app nor the database is going to be highly utilized so 
performance is not too much of a concern. Is there a way to simply force 
all data retrieval to always go to the database and not the cache?  I'm 
looking for some simple steps to follow and it's possible I've 
overlooked the obvious.

Thanks,

Andrew


On 09/12/16 02:04 AM, Andrus Adamchik wrote:
>> On Oct 25, 2016, at 3:30 PM, Hugi Thordarson <hu...@karlmenn.is> wrote:
>>
>> Hi all.
>> I\u2019m 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\u2019s 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
>
>
>


Re: Disabling caching for all entities in a certain DataMap

Posted by Andrus Adamchik <an...@objectstyle.org>.
> On Oct 25, 2016, at 3:30 PM, Hugi Thordarson <hu...@karlmenn.is> 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