From 189b81df09c3c48a35f1d36542ddc93c9258caf2 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sun, 12 Feb 2017 19:14:23 +0200 Subject: Avoid growing DirectoryObjectCache too much --- obnamlib/fmt_ga/tree.py | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'obnamlib/fmt_ga/tree.py') 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) -- cgit v1.2.1