From 903005a52830ba964583fb0c871c7bbf336770cb Mon Sep 17 00:00:00 2001 From: kevan <kevan@isnotajoke.com> Date: Sun, 5 Jul 2009 14:23:45 -0700 Subject: [PATCH] Add CachingDict dict subclass to dirnode.py --- src/allmydata/dirnode.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) 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 -- 2.45.2