tracking collection modification
Diez B. Roggisch
deets at nospam.web.de
Mon Sep 8 14:45:33 CEST 2008
usenet.tolomea at gmail.com wrote:
> On Sep 7, 8:54 pm, usenet.tolo... at gmail.com wrote:
>> I'm working on a remote object system, something kinda like Pyro.
>> For the purposes of caching I need to be able to tell if a given
>> dict / list / set has been modified.
>> Ideally what I'd like is for them to have a modification count
>> variable that increments every time the particular collection is
>> modified. Unfortunately I can't find anything like that and since this
>> needs to work for the regular normal list / dict / set objects
>> subclassing them to add the modification count isn't useful.
>> I realize I could take a copy and then compare the copy to the
>> original, but that's a fairly heavy handed approach and I was hoping
>> for something light and fast.
>> Does anyone have any suggestions on best to approach this?
> additionally I don't need to know if the things the list (etc)
> references have changed, only the list itself
No chance. E.g. ZODB is faced with the same problem and requires you to use
certain collection implementations to make this work.
And don't forget that such a scheme is hard to implement in the face of
concurrent access by various clients - as client connection has to keep
track of the last-modified-state separately.
I'd say that for small to medium-sized collections, it's faster to just
marshal them each time. Beyond that, make the heavy-handed checking - and
offer dirty-state-aware collection classes one can use to optimize specific
More information about the Python-list