From: kevan Date: Sun, 5 Jul 2009 21:23:45 +0000 (-0700) Subject: Add CachingDict dict subclass to dirnode.py X-Git-Url: https://git.rkrishnan.org/pf/content/en/service/something?a=commitdiff_plain;h=903005a52830ba964583fb0c871c7bbf336770cb;p=tahoe-lafs%2Ftahoe-lafs.git Add CachingDict dict subclass to dirnode.py --- diff --git a/src/allmydata/dirnode.py b/src/allmydata/dirnode.py index 8f72709b..302f8df5 100644 --- a/src/allmydata/dirnode.py +++ b/src/allmydata/dirnode.py @@ -21,6 +21,23 @@ from allmydata.util.netstring import netstring, split_netstring from allmydata.uri import NewDirectoryURI, LiteralFileURI, from_string from pycryptopp.cipher.aes import AES +class CachingDict(dict): + def __init__(self, *args): + super(CachingDict, self).__init__(*args) + self.serialized = {} + + def __setitem__(self, k, v): + super(CachingDict, self).__setitem__(k, v) + self.serialized[k] = None + + def get_both_items(self, k): + return (self.serialized.setdefault(k, None), + super(CachingDict, self).__getitem__(k)) + + def set_both_items(self, key, serialized, t): + self.serialized[key] = serialized + super(CachingDict, self).__setitem__(key, t) + class Deleter: def __init__(self, node, name, must_exist=True): self.node = node