You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Lon Varscsak <lo...@gmail.com> on 2016/04/20 00:50:41 UTC

Object relationship freshness

Hey guys,

I’m executing a query and then referencing the fetched object and some
relationships on the fetched object.  Later, I create a new ObjectContext
(old one is thrown away) and I issue the fetch again and I notice that the
relationship objects are not refreshed (weirdly I see one of the
relationship queries fire again, but not the other…either way both objects
“snapshots” (EOF term) are as they were originally).

I’m not caching any results, shouldn’t data go stale after it’s
ObjectContext is gone?

-Lon

Re: Object relationship freshness

Posted by Lon Varscsak <lo...@gmail.com>.
The problem with prefetching is that it means that every application needs
to assume that the data is dirty and know of every relationship.  Which is
problematic because 1) relationships can change over time and 2) I don’t
necessarily wan’t to prefetch every relationship.  I feel like that if I’m
using a new ObjectContext and those objects are in no other context that
the data should not be in memory to return stale data.

On Wed, Apr 20, 2016 at 12:44 AM, Andrus Adamchik <an...@objectstyle.org>
wrote:

> Which reminds me that, I need to replace doc examples with SelectQuery to
> use ObjectSelect :)
>
> Andrus
>
> > On Apr 20, 2016, at 10:42 AM, Adam Boyle <ab...@valsphere.com> wrote:
> >
> > I can confirm... prefetching is the way to go.
> https://cayenne.apache.org/docs/4.0/cayenne-guide/performance-tuning.html#prefetching
> >
> > I was having a similar issue where my most recently committed records
> were not showing up in subsequent queries. Prefetching is what fixed it for
> me. You can apply prefetching to ObjectSelect as well as SelectQuery as in
> the docs.
> >
> > ________________________________________
> > From: Andrus Adamchik <an...@objectstyle.org>
> > Sent: Wednesday, April 20, 2016 2:54 AM
> > To: user@cayenne.apache.org
> > Subject: Re: Object relationship freshness
> >
> >> *changing this to “false”
> >
> > While this may solve the immediate problem, turning off shared object
> cache is not terribly efficient. I would recommend against it.
> >
> >>>> weirdly I see one of the
> >>>> relationship queries fire again, but not the other…either way both
> objects
> >>>> “snapshots” (EOF term) are as they were originally
> >
> > If you actually see SQL in the logs that reads a relationship, it should
> absolutely refresh the cache.
> >
> > Generally if you don't want to-one relationships to be resolved from
> cache, the most reliable approach is to use prefetching on the query that
> fetched the root object.
> >
> > Andrus
> >
> >
> >
> >> On Apr 20, 2016, at 2:07 AM, Lon Varscsak <lo...@gmail.com>
> wrote:
> >>
> >> *changing this to “false”
> >>
> >> On Tue, Apr 19, 2016 at 4:07 PM, Lon Varscsak <lo...@gmail.com>
> >> wrote:
> >>
> >>> It looks like I had cayenne.DataDomain.sharedCache=true in my model.
> >>> Changing this to default solved my issue.  Seem reasonable?
> >>>
> >>> On Tue, Apr 19, 2016 at 3:50 PM, Lon Varscsak <lo...@gmail.com>
> >>> wrote:
> >>>
> >>>> Hey guys,
> >>>>
> >>>> I’m executing a query and then referencing the fetched object and some
> >>>> relationships on the fetched object.  Later, I create a new
> ObjectContext
> >>>> (old one is thrown away) and I issue the fetch again and I notice
> that the
> >>>> relationship objects are not refreshed (weirdly I see one of the
> >>>> relationship queries fire again, but not the other…either way both
> objects
> >>>> “snapshots” (EOF term) are as they were originally).
> >>>>
> >>>> I’m not caching any results, shouldn’t data go stale after it’s
> >>>> ObjectContext is gone?
> >>>>
> >>>> -Lon
> >>>>
> >>>
> >>>
>
>

Re: Object relationship freshness

Posted by Andrus Adamchik <an...@objectstyle.org>.
Which reminds me that, I need to replace doc examples with SelectQuery to use ObjectSelect :)

Andrus

> On Apr 20, 2016, at 10:42 AM, Adam Boyle <ab...@valsphere.com> wrote:
> 
> I can confirm... prefetching is the way to go. https://cayenne.apache.org/docs/4.0/cayenne-guide/performance-tuning.html#prefetching
> 
> I was having a similar issue where my most recently committed records were not showing up in subsequent queries. Prefetching is what fixed it for me. You can apply prefetching to ObjectSelect as well as SelectQuery as in the docs.
> 
> ________________________________________
> From: Andrus Adamchik <an...@objectstyle.org>
> Sent: Wednesday, April 20, 2016 2:54 AM
> To: user@cayenne.apache.org
> Subject: Re: Object relationship freshness
> 
>> *changing this to “false”
> 
> While this may solve the immediate problem, turning off shared object cache is not terribly efficient. I would recommend against it.
> 
>>>> weirdly I see one of the
>>>> relationship queries fire again, but not the other…either way both objects
>>>> “snapshots” (EOF term) are as they were originally
> 
> If you actually see SQL in the logs that reads a relationship, it should absolutely refresh the cache.
> 
> Generally if you don't want to-one relationships to be resolved from cache, the most reliable approach is to use prefetching on the query that fetched the root object.
> 
> Andrus
> 
> 
> 
>> On Apr 20, 2016, at 2:07 AM, Lon Varscsak <lo...@gmail.com> wrote:
>> 
>> *changing this to “false”
>> 
>> On Tue, Apr 19, 2016 at 4:07 PM, Lon Varscsak <lo...@gmail.com>
>> wrote:
>> 
>>> It looks like I had cayenne.DataDomain.sharedCache=true in my model.
>>> Changing this to default solved my issue.  Seem reasonable?
>>> 
>>> On Tue, Apr 19, 2016 at 3:50 PM, Lon Varscsak <lo...@gmail.com>
>>> wrote:
>>> 
>>>> Hey guys,
>>>> 
>>>> I’m executing a query and then referencing the fetched object and some
>>>> relationships on the fetched object.  Later, I create a new ObjectContext
>>>> (old one is thrown away) and I issue the fetch again and I notice that the
>>>> relationship objects are not refreshed (weirdly I see one of the
>>>> relationship queries fire again, but not the other…either way both objects
>>>> “snapshots” (EOF term) are as they were originally).
>>>> 
>>>> I’m not caching any results, shouldn’t data go stale after it’s
>>>> ObjectContext is gone?
>>>> 
>>>> -Lon
>>>> 
>>> 
>>> 


Re: Object relationship freshness

Posted by Adam Boyle <ab...@valsphere.com>.
I can confirm... prefetching is the way to go. https://cayenne.apache.org/docs/4.0/cayenne-guide/performance-tuning.html#prefetching

I was having a similar issue where my most recently committed records were not showing up in subsequent queries. Prefetching is what fixed it for me. You can apply prefetching to ObjectSelect as well as SelectQuery as in the docs.

________________________________________
From: Andrus Adamchik <an...@objectstyle.org>
Sent: Wednesday, April 20, 2016 2:54 AM
To: user@cayenne.apache.org
Subject: Re: Object relationship freshness

> *changing this to “false”

While this may solve the immediate problem, turning off shared object cache is not terribly efficient. I would recommend against it.

>>> weirdly I see one of the
>>> relationship queries fire again, but not the other…either way both objects
>>> “snapshots” (EOF term) are as they were originally

If you actually see SQL in the logs that reads a relationship, it should absolutely refresh the cache.

Generally if you don't want to-one relationships to be resolved from cache, the most reliable approach is to use prefetching on the query that fetched the root object.

Andrus



> On Apr 20, 2016, at 2:07 AM, Lon Varscsak <lo...@gmail.com> wrote:
>
> *changing this to “false”
>
> On Tue, Apr 19, 2016 at 4:07 PM, Lon Varscsak <lo...@gmail.com>
> wrote:
>
>> It looks like I had cayenne.DataDomain.sharedCache=true in my model.
>> Changing this to default solved my issue.  Seem reasonable?
>>
>> On Tue, Apr 19, 2016 at 3:50 PM, Lon Varscsak <lo...@gmail.com>
>> wrote:
>>
>>> Hey guys,
>>>
>>> I’m executing a query and then referencing the fetched object and some
>>> relationships on the fetched object.  Later, I create a new ObjectContext
>>> (old one is thrown away) and I issue the fetch again and I notice that the
>>> relationship objects are not refreshed (weirdly I see one of the
>>> relationship queries fire again, but not the other…either way both objects
>>> “snapshots” (EOF term) are as they were originally).
>>>
>>> I’m not caching any results, shouldn’t data go stale after it’s
>>> ObjectContext is gone?
>>>
>>> -Lon
>>>
>>
>>

Re: Object relationship freshness

Posted by Andrus Adamchik <an...@objectstyle.org>.
> *changing this to “false”

While this may solve the immediate problem, turning off shared object cache is not terribly efficient. I would recommend against it. 

>>> weirdly I see one of the
>>> relationship queries fire again, but not the other…either way both objects
>>> “snapshots” (EOF term) are as they were originally

If you actually see SQL in the logs that reads a relationship, it should absolutely refresh the cache.

Generally if you don't want to-one relationships to be resolved from cache, the most reliable approach is to use prefetching on the query that fetched the root object. 

Andrus



> On Apr 20, 2016, at 2:07 AM, Lon Varscsak <lo...@gmail.com> wrote:
> 
> *changing this to “false”
> 
> On Tue, Apr 19, 2016 at 4:07 PM, Lon Varscsak <lo...@gmail.com>
> wrote:
> 
>> It looks like I had cayenne.DataDomain.sharedCache=true in my model.
>> Changing this to default solved my issue.  Seem reasonable?
>> 
>> On Tue, Apr 19, 2016 at 3:50 PM, Lon Varscsak <lo...@gmail.com>
>> wrote:
>> 
>>> Hey guys,
>>> 
>>> I’m executing a query and then referencing the fetched object and some
>>> relationships on the fetched object.  Later, I create a new ObjectContext
>>> (old one is thrown away) and I issue the fetch again and I notice that the
>>> relationship objects are not refreshed (weirdly I see one of the
>>> relationship queries fire again, but not the other…either way both objects
>>> “snapshots” (EOF term) are as they were originally).
>>> 
>>> I’m not caching any results, shouldn’t data go stale after it’s
>>> ObjectContext is gone?
>>> 
>>> -Lon
>>> 
>> 
>> 


Re: Object relationship freshness

Posted by Lon Varscsak <lo...@gmail.com>.
*changing this to “false”

On Tue, Apr 19, 2016 at 4:07 PM, Lon Varscsak <lo...@gmail.com>
wrote:

> It looks like I had cayenne.DataDomain.sharedCache=true in my model.
> Changing this to default solved my issue.  Seem reasonable?
>
> On Tue, Apr 19, 2016 at 3:50 PM, Lon Varscsak <lo...@gmail.com>
> wrote:
>
>> Hey guys,
>>
>> I’m executing a query and then referencing the fetched object and some
>> relationships on the fetched object.  Later, I create a new ObjectContext
>> (old one is thrown away) and I issue the fetch again and I notice that the
>> relationship objects are not refreshed (weirdly I see one of the
>> relationship queries fire again, but not the other…either way both objects
>> “snapshots” (EOF term) are as they were originally).
>>
>> I’m not caching any results, shouldn’t data go stale after it’s
>> ObjectContext is gone?
>>
>> -Lon
>>
>
>

Re: Object relationship freshness

Posted by Lon Varscsak <lo...@gmail.com>.
It looks like I had cayenne.DataDomain.sharedCache=true in my model.
Changing this to default solved my issue.  Seem reasonable?

On Tue, Apr 19, 2016 at 3:50 PM, Lon Varscsak <lo...@gmail.com>
wrote:

> Hey guys,
>
> I’m executing a query and then referencing the fetched object and some
> relationships on the fetched object.  Later, I create a new ObjectContext
> (old one is thrown away) and I issue the fetch again and I notice that the
> relationship objects are not refreshed (weirdly I see one of the
> relationship queries fire again, but not the other…either way both objects
> “snapshots” (EOF term) are as they were originally).
>
> I’m not caching any results, shouldn’t data go stale after it’s
> ObjectContext is gone?
>
> -Lon
>