diff options
author | Lars Wirzenius <liw@liw.fi> | 2017-02-12 19:14:23 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2017-02-12 19:14:23 +0200 |
commit | 189b81df09c3c48a35f1d36542ddc93c9258caf2 (patch) | |
tree | 234b4188eecd19239995d7885047083f07f2c9d2 | |
parent | a906a2db457b92ff1b0b0460d015e8fca2fc0abd (diff) | |
download | obnam-189b81df09c3c48a35f1d36542ddc93c9258caf2.tar.gz |
Avoid growing DirectoryObjectCache too much
-rw-r--r-- | obnamlib/fmt_ga/tree.py | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/obnamlib/fmt_ga/tree.py b/obnamlib/fmt_ga/tree.py index 7801b847..a8798c78 100644 --- a/obnamlib/fmt_ga/tree.py +++ b/obnamlib/fmt_ga/tree.py @@ -159,12 +159,20 @@ class DirectoryObjectCache(object): def __init__(self): self.clear() + self._max_objs = 10**5 + + def _clear_immutable(self): # pragma: no cover + if len(self._objs) >= self._max_objs: + for pathname, dirobj in self._objs.items(): + if not dirobj.is_mutable(): + del self._objs[pathname] def clear(self): self._objs = {} def set(self, pathname, dir_obj): self._objs[pathname] = dir_obj + self._clear_immutable() def get(self, pathname): return self._objs.get(pathname) |