Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #105454
| Path | csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | dieter <dieter@handshake.de> |
| Newsgroups | comp.lang.python |
| Subject | Re: Static caching property |
| Date | Tue, 22 Mar 2016 09:30:03 +0100 |
| Lines | 22 |
| Message-ID | <mailman.487.1458635413.12893.python-list@python.org> (permalink) |
| References | <35a5c4206a0c40e584d62d5d37b068b3@activenetwerx.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=us-ascii |
| X-Trace | news.uni-berlin.de pTj947olN4UPYVXFIoBaNQ8SywmJEi86E3uLdyQgGNJg== |
| Cancel-Lock | sha1:B8o3yFcCN3wbF9iF5MLtvbUpgg0= |
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'cache': 0.05; 'none:': 0.05; 'defines': 0.07; 'instances.': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'def': 0.13; '@classmethod': 0.16; 'email name:"': 0.16; 'instances,': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'received:t-ipconnect.de': 0.16; 'attribute': 0.18; 'this:': 0.23; 'header:User-Agent:1': 0.26; 'header:X-Complaints-To:1': 0.26; 'class': 0.33; 'instance': 0.35; 'something': 0.35; 'should': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'method': 0.37; 'received:org': 0.37; 'charset:us-ascii': 0.37; 'to:addr:python.org': 0.40; 'received:de': 0.40; 'determine': 0.61; 'results': 0.66 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| X-Gmane-NNTP-Posting-Host | p57b39509.dip0.t-ipconnect.de |
| User-Agent | Gnus/5.1008 (Gnus v5.10.8) XEmacs/21.4.22 (linux) |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.21 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Xref | csiph.com comp.lang.python:105454 |
Show key headers only | View raw
"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 comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Static caching property dieter <dieter@handshake.de> - 2016-03-22 09:30 +0100
csiph-web