Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #105454 > unrolled thread
| Started by | dieter <dieter@handshake.de> |
|---|---|
| First post | 2016-03-22 09:30 +0100 |
| Last post | 2016-03-22 09:30 +0100 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Static caching property dieter <dieter@handshake.de> - 2016-03-22 09:30 +0100
| From | dieter <dieter@handshake.de> |
|---|---|
| Date | 2016-03-22 09:30 +0100 |
| Subject | Re: Static caching property |
| Message-ID | <mailman.487.1458635413.12893.python-list@python.org> |
"Joseph L. Casale" <jcasale@activenetwerx.com> writes:
> ...
> I need to cache the results of a method on a class across all instances.
If a method call on any instance defines the return value for
all instances, then this method likely should be a class method --
and use a class attribute to store the result -- something like this:
class C(object):
_cache = {}
@classmethod
def f(cls, ...):
... determine cache key `key` ...
v = cls._cache.get(key)
if v is None:
v = cls._cache[key] = ...
return v
It will work also without the "@classmethod".
Back to top | Article view | comp.lang.python
csiph-web