On 18/02/2023 17:19, Albert-Jan Roskam wrote:
On Feb 18, 2023 17:28, Rob Cliffe via Python-list
wrote:
On 18/02/2023 15:29, Thomas Passin wrote:
> On 2/18/2023 5:38 AM, Albert-Jan Roskam wrote:
>> I sometimes use this trick, which I learnt from a book by
Martelli.
On Feb 18, 2023 17:28, Rob Cliffe via Python-list
wrote:
On 18/02/2023 15:29, Thomas Passin wrote:
> On 2/18/2023 5:38 AM, Albert-Jan Roskam wrote:
>> I sometimes use this trick, which I learnt from a book by
Martelli.
>> Instead of try/except, membership te
On 18/02/2023 15:29, Thomas Passin wrote:
On 2/18/2023 5:38 AM, Albert-Jan Roskam wrote:
I sometimes use this trick, which I learnt from a book by Martelli.
Instead of try/except, membership testing with "in"
(__contains__) might
be faster. Probably "depends". Matter of measuring
On 2/18/2023 5:38 AM, Albert-Jan Roskam wrote:
I sometimes use this trick, which I learnt from a book by Martelli.
Instead of try/except, membership testing with "in" (__contains__) might
be faster. Probably "depends". Matter of measuring.
def somefunc(arg, _cache={}):
if
I sometimes use this trick, which I learnt from a book by Martelli.
Instead of try/except, membership testing with "in" (__contains__) might
be faster. Probably "depends". Matter of measuring.
def somefunc(arg, _cache={}):
if len(_cache) > 10 ** 5:
_cache.pop()
if value in recent:
if (r := cache.get(value)) != value * value:
raise ValueError(f"Cache missing recent {value} {r}")
else:
if cache.get(value) != None:
raise ValueError(f"Cache includes old {value}")
From: Pyt
else:
if cache.get(value) != None:
raise ValueError(f"Cache includes old {value}")
From: Python-list on
behalf of Dino
Date: Wednesday, February 15, 2023 at 3:07 PM
To: python-list@python.org
Subject: Re: LRU cache
*** Attention: This is an external email.
Thank you Mats, Avi and Chris
btw, functools.lru_cache seems rather different from what I need, but
maybe I am missing something. I'll look closer.
On 2/14/2023 7:36 PM, Mats Wichmann wrote:
On 2/14/23 15:07, Dino wrote:
--
https://mail.python.org/mailman/listinfo/python-list
?) to
roll your own, my memory tells me the RealPython crew did a tutorial on
implementing an LRU cache, might be worth a look (not sure if this is
one of the all-free ones, or one of the
must-be-a-paid-subscriber-to-get-the-advanced-stuff ones.
--
https://mail.python.org/mailman/listinfo/python-list
elico
Sent: Tuesday, February 14, 2023 5:46 PM
To: python-list@python.org
Subject: Re: LRU cache
On Wed, 15 Feb 2023 at 09:37, Dino wrote:
>
>
> Here's my problem today. I am using a dict() to implement a quick and
> dirty in-memory cache.
>
> I am stopping adding elem
immediately as it is least recently used if placed at the end.
It may be an Ordered Dict is one solution as shown here:
https://www.geeksforgeeks.org/lru-cache-in-python-using-ordereddict/
-Original Message-
From: Python-list On
Behalf Of Dino
Sent: Tuesday, February 14, 2023 5:07 PM
To
On Wed, 15 Feb 2023 at 09:37, Dino wrote:
>
>
> Here's my problem today. I am using a dict() to implement a quick and
> dirty in-memory cache.
>
> I am stopping adding elements when I am reaching 1000 elements (totally
> arbitrary number), but I would like to have something slightly more
> sophist
Here's my problem today. I am using a dict() to implement a quick and
dirty in-memory cache.
I am stopping adding elements when I am reaching 1000 elements (totally
arbitrary number), but I would like to have something slightly more
sophisticated to free up space for newer and potentially m
#simple, but effective (sometimes)
class ICORCache:
def __init__(self,agetfunc,amaxlen=100):
self.GetValue=agetfunc
self.MaxLen=amaxlen
self.VDict={}
self.KDict={}
self.VPos=1
self.AccessRatio=0
self.HitRatio=0
def __getitem__(self,key):
self.A
Nikita the Spider <[EMAIL PROTECTED]> writes:
> This one works for me:
> http://www.webfast.com/~skip/python/Cache.py
Thanks, this one keeps track of the actual clock time rather than just
the relative age of cache entries, and has kind of a weird ageing
mechanism, building and sorting an O(n) siz
[EMAIL PROTECTED] (Alex Martelli) writes:
> So what's wrong with Evan Prodromou's lrucache.py module that's in pypi?
> Haven't used it, but can't see anything wrong at a glance.
Thanks, I wasn't aware of that one. I notice two things about it:
1) it's under a GPL-incompatible license (therefore a
In article <[EMAIL PROTECTED]>,
Paul Rubin <http://[EMAIL PROTECTED]> wrote:
> Anyone got a favorite LRU cache implementation? I see a few in google
> but none look all that good. I just want a dictionary indexed by
> strings, that remembers the last few thousand entries
Paul Rubin <http://[EMAIL PROTECTED]> wrote:
> Anyone got a favorite LRU cache implementation? I see a few in google
> but none look all that good. I just want a dictionary indexed by
> strings, that remembers the last few thousand entries I put in it.
So what's wrong w
Thomas Wittek wrote:
> Paul Rubin schrieb:
>> Anyone got a favorite LRU cache implementation? I see a few in google
>> but none look all that good. I just want a dictionary indexed by
>> strings, that remembers the last few thousand entries I put in it.
>
> I d
Paul Rubin schrieb:
> Anyone got a favorite LRU cache implementation? I see a few in google
> but none look all that good. I just want a dictionary indexed by
> strings, that remembers the last few thousand entries I put in it.
I don't know a module for that (although it might
Anyone got a favorite LRU cache implementation? I see a few in google
but none look all that good. I just want a dictionary indexed by
strings, that remembers the last few thousand entries I put in it.
It actually looks like this is almost a FAQ. A well-written
implementation would probably
Evan> http://www.python.org/pypi?:action=display&name=lrucache&version=0.2
skip> Couldn't get to your website, but I've been using this one I wrote
skip> for several years:
skip> http://www.webfast.com/~skip/python/Cache.py
skip> I'm just coming to this thread, so I don'
Evan> I agree that LRU caches are a data structure too frequently
Evan> re-implemented in Python. I'd also like to see a "standard" cache
Evan> package, either as part of the standard library or elsewhere. To
Evan> that end, I've just uploaded an
23 matches
Mail list logo