Re: LRU cache

2023-02-22 Thread Rob Cliffe via Python-list
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.

Re: LRU cache

2023-02-18 Thread Albert-Jan Roskam
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

Re: LRU cache

2023-02-18 Thread Rob Cliffe via Python-list
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

Re: LRU cache

2023-02-18 Thread Thomas Passin
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

Re: LRU cache

2023-02-18 Thread Albert-Jan Roskam
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()    

Re: LRU cache

2023-02-17 Thread Dino
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

Re: LRU cache

2023-02-16 Thread Weatherby,Gerard
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.

Re: LRU cache

2023-02-15 Thread Dino
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

Re: LRU cache

2023-02-15 Thread Mats Wichmann
?) 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

RE: LRU cache

2023-02-14 Thread avi.e.gross
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

RE: LRU cache

2023-02-14 Thread avi.e.gross
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

Re: LRU cache

2023-02-14 Thread Chris Angelico
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

LRU cache

2023-02-14 Thread Dino
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

Re: LRU cache?

2007-08-20 Thread qyloxe
#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

Re: LRU cache?

2007-08-12 Thread Paul Rubin
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

Re: LRU cache?

2007-08-12 Thread Paul Rubin
[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

Re: LRU cache?

2007-08-12 Thread Nikita the Spider
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

Re: LRU cache?

2007-08-11 Thread Alex Martelli
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

Re: LRU cache?

2007-08-11 Thread Steve Holden
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

Re: LRU cache?

2007-08-11 Thread Thomas Wittek
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

LRU cache?

2007-08-11 Thread Paul Rubin
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

Re: LRU cache (and other things missing from the standard library ...)

2007-03-30 Thread skip
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'

Re: LRU cache (and other things missing from the standard library ...)

2007-03-30 Thread skip
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