You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by "Durchholz, Joachim" <Jo...@hennig-fahrzeugteile.de> on 2011/08/18 12:58:28 UTC

Two caches - what are the issues?

http://cayenne.apache.org/doc30/caching-and-fresh-data.html has this to say:

> [...] two types of caches (individual object and query results) are separate from each other

This leaves me wondering. Does this mean I can have two objects that map to the same database record, one in the individual object cache and one in the query result cache?
That would be really bad, because I'd had to be ultra-careful to always work either in individual object or in query results land; modifications to one object would been to be applied to the other, and if I make a mistake there I get all the fun of inconsistent cache adventures.

Am I misinterpreting something?
If not: how do peple deal with it? What are the best practices here?

Regards,
Jo

RE: Two caches - what are the issues?

Posted by "Durchholz, Joachim" <Jo...@hennig-fahrzeugteile.de>.
> > This leaves me wondering. Does this mean I can have two objects that map to the same database record, one in the individual object cache and one in the query result cache?
> 
> No. The DataObject uniquing is guaranteed per ObjectContext by Cayenne regardless of the caching. 

Phew :-)

I have a few more questions if you don't mind. These aren't as important as the above one, I'm just checking how inaccurate my mental model of Cayenne is. So even a response of "you're asking the wrong questions" might be helpful.

Here goes:

Do both caches contain just persistent objects?
Things I can imagine for the query cache:
- Scalar results, such as the result from a SELECT COUNT(*)
- Prepared queries (I guess it's actually associated with the ObjectContext)
- Result sets, scrollable ones in particular (probably in ObjectContext, too)

If both caches contain persistent objects: from the answer above I conclude that the same object can be in both caches.
If an object is culled from one of the caches, is it removed from the other as well, or is it kept?

Regards,
Jo

Re: Two caches - what are the issues?

Posted by Andrus Adamchik <an...@objectstyle.org>.
On Aug 18, 2011, at 1:58 PM, Durchholz, Joachim wrote:

> This leaves me wondering. Does this mean I can have two objects that map to the same database record, one in the individual object cache and one in the query result cache?

No. The DataObject uniquing is guaranteed per ObjectContext by Cayenne regardless of the caching. 

> Am I misinterpreting something?
> If not: how do peple deal with it? What are the best practices here?

Usually there's nothing to deal with really. The main drawback here is that object cache is not pluggable and not managed (you can't set expiration policies, it is just an LRU). But other than that it is transparent.

Andrus