Peter Wilkinson wrote:
> Hi,
> I'm currently in the situation of needing to find an elegant way of
> having multiple processes all use caching turned on and yet have them
> track changes made in one of the other processes.
>
> eg.
> Process A is running doing mainly reads, while process B is occasionally
> making changes, process A in this situation would ideally be able to
> deal with this and see the changed objects.
>
> Currently I'm doing this by assuming and accepting that process B will
> occasionally be out of sync with he reality of the database by having it
> having it kill itself periodically. Now this works but is far from
> elegant and ends up defeating the use of a cache which is extremely
> handy in a process that is really only deals with the database read-only.
>
> How have others dealt with this? Is something like putting the cache in
> shared memory feasible?
You can expire a single object using .expire(), which will cause it to
resync with the database when you next use the object. You can expire
all the objects as well, though there's no direct method for it right
now. Look at DBConnection.Transaction.rollback for that.
If you wanted some sort of event-based expiration, process A would have
to be listening to process B in some way, and your objects in process B
would have to have some notification code added. That's a little more
complicated, but it would keep the two processes solidly in sync.
Ian
|