aybekckaya / sqlitepersistentobjects

Automatically exported from code.google.com/p/sqlitepersistentobjects
0 stars 1 forks source link

Persistent object not being removed from in-memory cache after delete #11

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Save a persistent object
2. Query and show that object
3. Delete that persistent object
4. Query and show no objects
5. Save a new persistent object
6. Query and show that object
7. This "new" object is the old object cached

What is the expected output? What do you see instead?
Expect to see the new object. Instead, saw the old cached object. This is 
probably happening 
because the primary key is being reused when the new object is saved. Since the 
cache wasn't 
cleared of the deleted object, the old primary key is being found with the 
cached old object.

What version of the product are you using? On what operating system?
Latest from trunk.

Please provide any additional information below.
I added the following line of code at line 777 in SQLitePersistentObject.m:

[SQLitePersistentObject unregisterObject:self];

Right after it executes the delete query. This works but may not be the best 
way. For example, 
should child persistent objects also be removed from the cache?

Original issue reported on code.google.com by d...@mac.com on 27 Oct 2008 at 6:51

GoogleCodeExporter commented 8 years ago
Jeff, what do you think about the proposed solution for this?  I'll knock this 
one out if you don't see any 
problems with it.  

Turns out this issue explains a bug in my own program, in which I add a Person, 
delete that person, and add 
another Person with a different name.  After that second Person is added, it 
shows the name of the first Person 
instead of the first.  

Original comment by kennethr...@gmail.com on 23 Jan 2009 at 8:55

GoogleCodeExporter commented 8 years ago
It looks fine, don't think there's a need to worry about the child objects - if 
cascade is called, this same method 
will get called on all the children, if they didn't request a cascading delete 
then we definitely wouldn't want to 
delete the children.

Original comment by jeff.lam...@gmail.com on 23 Jan 2009 at 9:07

GoogleCodeExporter commented 8 years ago
Resolved by ensuring the deleted object is unregistered during the deletion 
process.  Note that given the 
methods currently available that this requires the object to be loaded into 
memory in the event it wasn't already, 
as would possibly be the case when deleting by PK.

Confirmed this resolved my display issue, in which adding an object, deleting 
it, and then adding another caused 
the new object to display as the original.

Original comment by kennethr...@gmail.com on 23 Jan 2009 at 9:58