Message92761
I think you're misquoting Python's shelve module documentation in your
first sentence. The documentation says:
"By default modified objects are written only when assigned to the shelf
[...]. If the optional writeback parameter is set to True, all entries
accessed are cached in memory, and written back at close time [...]."
The emphasis should be on the word "only:" it does *always* write to the
database when assigned to the shelf but, iff writeback=True, *also* to
the cache.
Also consider the consequences of *only* caching keys:
(a) __contains__ and has_key have to consult the dict and the cache for
membership tests.
(b) keys and __len__ need to compute a union of both sources.
(c) __delitem__ is no longer guaranteed to fail on the cache if it
failed for the database.
I admit the docs could spell this out more clearly. I attached a patch
ensuring the behaviour I described in a test and updating the docs.
(Note: shelve is no extension module -- it's part of the stdlib. Patch
applies to 3.x as well.) |
|
Date |
User |
Action |
Args |
2009-09-17 13:09:18 | lehmannro | set | recipients:
+ lehmannro, aleax, jherskovic |
2009-09-17 13:09:18 | lehmannro | set | messageid: <1253192958.72.0.854180767169.issue5754@psf.upfronthosting.co.za> |
2009-09-17 13:09:17 | lehmannro | link | issue5754 messages |
2009-09-17 13:09:16 | lehmannro | create | |
|