MCPcopy Create free account
hub / github.com/dabeaz/python-cookbook / CachedSpamManager

Class CachedSpamManager

src/8/creating_cached_instances/example2.py:3–12  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1import weakref
2
3class CachedSpamManager:
4 def __init__(self):
5 self._cache = weakref.WeakValueDictionary()
6 def get_spam(self, name):
7 if name not in self._cache:
8 s = Spam(name)
9 self._cache[name] = s
10 else:
11 s = self._cache[name]
12 return s
13
14class Spam:
15 def __init__(self, name):

Callers 1

example2.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected