0

Here's my situation; let's assume I have 2 tables; employee and responsibility where Responsibility.employee_id = employee.id.

Sometimes we need to update Responsibility.employee_id manually and there's no way to avoid this, it needs to be done manually sometimes. When we do, cayenne doesn't see the need to re-fetch the object since it's not aware that it was updated.

Question: I want to disable caching in cayenne completely. I want everything to be fetched from the database. Is this possible?

Trying...
  • 127
  • 9
  • You can disable your cache using the Cayenne Modeler, and going into the DataDomain Configuration. Right below that is the Cache Configuration, change the Size of Object Cache option to 0. I'm not sure what you mean by changing the id manually. Maybe some code example? – Tuan Apr 21 '15 at 19:50
  • I meant changing with a query. For example: "UPDATE responsibility set employee.id=123 where id=5;" – Trying... Apr 22 '15 at 12:23
  • I think your suggestion will work for me. I'm going to give it a try. One more question (I"m also going to add this to my original post), what does 'Use Shared Cache' do? From what I understand, setting 'Size of Object Cache' to 0 will pretty much disable shared cache, right? Because cayenne will never reuse an object to cause stale data. – Trying... Apr 22 '15 at 12:32
  • Could you narrow down your question to _one_ actual question? 2 question in one doesn't really fit the Stack Overflow format. – Magnilex Apr 23 '15 at 20:28

1 Answers1

0

Fully disabling caching is a loaded question. It can mean different things in different situations. Instead I will answer how to refresh your relationship. The solution to this is using prefetching when selecting your objects. E.g.:

SelectQuery query = new SelectQuery(Responsibility.class);
query.addPrefetch("employee");
List<Responsibility> responsibilities = context.performQuery(query);

The above gives you fresh Responsibility objects, and refreshes its relationship to Employee.

andrus_a
  • 2,528
  • 1
  • 16
  • 10
  • Thank for your answer. I've actually been using this. There are so many relationships in the database so I'm ending up with a lot of extra code. I just want to turn caching off. Anytime I want to get an object, it should come from the database – Trying... Apr 22 '15 at 12:22
  • Ok, then start with a fresh ObjectContext every time. Then the objects will come "bare" from the query, not including any relationships. – andrus_a Apr 22 '15 at 13:41
  • Will setting 'Size of Object Cache' to 0 do the trick? I feel like that would mean no objects are stored in the cache so anytime I get an object through Cayenne, it should be coming from the database – Trying... Apr 22 '15 at 13:49
  • Setting 'Size of Object Cache' to 0 will NOT do the trick. Don't have space here to fully explain Cayenne policies for caching various parts of the object graph. Subscribe to Cayenne user@ list if you care for details. But in short, objects *are* coming from DB, but their relationships are not, unless you use prefetching. So I strongly suggest you keep doing that. This gives you full control over what to refresh as well as optimal performance for reading relationships. – andrus_a Apr 22 '15 at 14:46
  • Ok. I have over 3000 relationships in the database. Is there a way to get Cayenne to prefetch everything by default? So when I wanna make changes I'll use removePrefetch() to exclude what doesn't need to be prefetched. – Trying... Apr 22 '15 at 18:19
  • Perhaps you can join Cayenne user@ mailing list and explain your app in more detail, and we can discuss a proper Cayenne architecture for it. It is hard to answer such a "global" question without understanding the big picture, and I feel like we are hitting the limits of stackoverflow platform here. I am involved with many apps with hundreds of entities and thousands of relationships and fine-grained cache control. Yet we never felt we needed to invalidate all relationships unconditionally. – andrus_a Apr 23 '15 at 07:32