Module: check_mk
Branch: master
Commit: 8f51c35c1cf0e5191dce75cefa352d30b915bf6b
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=8f51c35c1cf0e5…
Author: Andreas Boesl <ab(a)mathias-kettner.de>
Date: Wed Jan 16 10:32:15 2019 +0100
caching.py: minor performance improvements
Change-Id: Ic0deead0258365682b4bb73a311bff2d6e48dc4e
---
cmk_base/caching.py | 60 +++++++++++++++++++++++++++--------------------------
1 file changed, 31 insertions(+), 29 deletions(-)
diff --git a/cmk_base/caching.py b/cmk_base/caching.py
index eb553e2..fa2de29 100644
--- a/cmk_base/caching.py
+++ b/cmk_base/caching.py
@@ -87,41 +87,43 @@ class Cache(object):
self._populated = False
-# Just a small wrapper round a dict to get some caching specific functionality
-# for analysis etc.
class DictCache(dict, Cache):
- def __init__(self, *args, **kwargs):
- super(DictCache, self).__init__(*args, **kwargs)
- self._num_hits = 0
- self._num_misses = 0
- self._num_sets = 0
-
- def __getitem__(self, y):
- try:
- result = super(DictCache, self).__getitem__(y)
- self._num_hits += 1
- return result
- except KeyError:
- self._num_misses += 1
- raise
-
- def __setitem__(self, i, y):
- self._num_sets += 1
- super(DictCache, self).__setitem__(i, y)
-
- def get_stats(self):
- return {
- "sets": self._num_sets,
- "hits": self._num_hits,
- "misses": self._num_misses,
- "items": len(self),
- }
-
def clear(self):
super(DictCache, self).clear()
self.set_not_populated()
+## Just a small wrapper round a dict to get some caching specific functionality
+## for analysis etc.
+#class DictCacheStats(DictCache):
+# def __init__(self, *args, **kwargs):
+# super(DictCacheStats, self).__init__(*args, **kwargs)
+# self._num_hits = 0
+# self._num_misses = 0
+# self._num_sets = 0
+#
+# def __getitem__(self, y):
+# try:
+# result = super(DictCacheStats, self).__getitem__(y)
+# self._num_hits += 1
+# return result
+# except KeyError:
+# self._num_misses += 1
+# raise
+#
+# def __setitem__(self, i, y):
+# self._num_sets += 1
+# super(DictCacheStats, self).__setitem__(i, y)
+#
+# def get_stats(self):
+# return {
+# "sets": self._num_sets,
+# "hits": self._num_hits,
+# "misses": self._num_misses,
+# "items": len(self),
+# }
+
+
class SetCache(set, Cache):
def clear(self):
super(SetCache, self).clear()