>From what I gather, it seems that this block of code is what invalidates 
all the current cached values of the getters during a save. 

- (void) didSave {

 

    if (!_needsSave || (!_changedNames && !_changedAttachments)) 

        return; 

    _isNew = NO; 

    _properties = nil; // This line of code invalidates all currently 
accessed values for model getters.

    _changedNames = nil; 

    _changedAttachments = nil; 

    self.needsSave = NO; 

}

*Do you think it would be unreasonable to comment out this one line of 
code, or will this cause a butterfly effect in the CBLModel code with 
foreseen consequences?*

I was worried that it might screw up something with upstream changes being 
pushed down to the device, but I noticed that _properties is invalidated in 
that block of code anyways, and see that is necessary so the code will 
start using the new data and not stale data.

// Respond to an external change (likely from sync). This is called by my 
CBLDocument.

 

- (void) CBLDocument: (CBLDocument*)doc didChange:(CBLDatabaseChange*)change 
{ 

    ...     

    // Remove unchanged cached values in _properties: 

    if (_changedNames && _properties) { 

        NSMutableSet* removeKeys = [NSMutableSet setWithArray: [_properties 
allKeys]]; 

        [removeKeys minusSet: _changedNames]; 

        [_properties removeObjectsForKeys: removeKeys.allObjects];    // 
Only remove cached property values that haven't changed 

    } else { 

        _properties = nil;     // In the case of only getter cached values, 
delete all cached values so they will be reloaded from the document 

    }

...

}


I really appreciate all your help and this library has been a fantastic 
addition to my app.

Cheers,
Ragu


On Sunday, May 4, 2014 3:28:49 PM UTC-7, Ragu Vijaykumar wrote:
>
> Thanks for the input. One follow-up question that I've seen one other ask 
> in the Github issues, but not seen answered. Why are cached property values 
> of CBLModels discarded on save?
>
> One of the performance issues I've been running into is that I 
> periodically save my CBLModels when my user leaves different view 
> controllers. However, this invalidates all the currently accessed values 
> for properties, and when I call the getters on these properties, recreating 
> their values from the document is expensive. Is there a workaround for this?
>
> Cheers,
> Ragu
>
> On Sunday, May 4, 2014 11:32:38 AM UTC-7, Jens Alfke wrote:
>>
>>
>> On May 4, 2014, at 4:10 AM, Ragu Vijaykumar <[email protected]> wrote:
>>
>> *I was wondering if there might be any bad side-effects if I were to 
>> create an NSCache for my read-only CBLModels?* 
>>
>>
>> That sounds reasonable. I don’t think there would be any bad side 
>> effects, other than increased memory usage of course. CBLDatabase does 
>> something similar, keeping an NSMutableSet of models with unsaved changes 
>> so they won’t be dealloced before they can be saved.
>>
>> the models have strong pointers to the CBLDocuments, so as long as they 
>> aren't dealloc'd, the documents won't be evicted from the cache.
>>
>>
>> Right.
>>
>> —Jens
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Couchbase Mobile" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/mobile-couchbase/27be8615-0644-4d12-add6-7c7a28314f3a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to