Roberto Perillo wrote:When you are creating the record, remember that is has already been read
I don't agree because when you say all you know is that the record 2 in the cache needs to be saved in the database file (if it was null you would just need to update the deletedFlag). But you do not know if this record was created as new one and replaced the deleted one. Let's try with an example. After some time, someone calls create(record) so Now, when you store objects back in the file (i.e when stopping the server): the condition is true because you replaced the deleted record with a new one in the cache but in the database file recNo 2 is still marekd as deleted. So you have no idea that this record replaced the deleted one and you need to check the flag in the file and update it accordingly.
Roberto Perillo wrote:
when you say
then it wasn't deleted when you first read it, and thus, you don't have to verify the deleted flag again.
Roel De Nijs wrote:I just iterate thorugh my cache and if a record is deleted, I just write the delete flag and an empty record; when the record is not deleted, I just write the valid flag and the actual contents of the record.
When evil is afoot and you don't have any arms you gotta be hip and do the legwork, but always kick some ... tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koophttps://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton