[Raymond Hettinger]
> >class Cache(dict):
> >def __init__(self, n, *args, **kwds):
> >self.n = n
> >self.queue = collections.deque()
> >dict.__init__(self, *args, **kwds)
[Bengt Richter]
> Minor comment: There is a potential name collision problem for keyword
> n=som
On Sat, 23 Jul 2005 20:07:25 -0600, Steven Bethard <[EMAIL PROTECTED]> wrote:
>[Raymond Hettinger]
>>>class Cache(dict):
>>> def __init__(self, n, *args, **kwds):
>>> self.n = n
>>> self.queue = collections.deque()
>>> dict.__init__(self, *args, **kwds)
>
>[Bengt Richter]
>> Mi
[Raymond Hettinger]
>>class Cache(dict):
>> def __init__(self, n, *args, **kwds):
>> self.n = n
>> self.queue = collections.deque()
>> dict.__init__(self, *args, **kwds)
[Bengt Richter]
> Minor comment: There is a potential name collision problem for keyword
> n=something,
>
On 21 Jul 2005 19:29:32 -0700, "Raymond Hettinger" <[EMAIL PROTECTED]> wrote:
>[Will McGugan]
>> I need a collection class that behaves like a dictionary but when it
>> reaches 'n' items it discards the oldest item so that the length never
>> goes above 'n'. (Its for caching search results)
>
>
>i
Will McGugan wrote:
>> You want a Least Recently Used, or LRU, cache. Here's one:
>>
> Thanks. I found the one I saw originally in the Python Cookbook. Only
> they call it a FIFO cache.
A FIFO cache is different, as gene tani points out. You need to consider
which one it is you want.
--
Mich
On 7/21/05, Michael Hoffman <[EMAIL PROTECTED]> wrote:
> Will McGugan wrote:
>
> > I need a collection class that behaves like a dictionary but when it
> > reaches 'n' items it discards the oldest item so that the length never
> > goes above 'n'. (Its for caching search results)
> >
> > I have a v
Michael Hoffman wrote:
> Will McGugan wrote:
>
>> I need a collection class that behaves like a dictionary but when it
>> reaches 'n' items it discards the oldest item so that the length never
>> goes above 'n'. (Its for caching search results)
>>
>> I have a vague memory of a module that does t
[Will McGugan]
> I need a collection class that behaves like a dictionary but when it
> reaches 'n' items it discards the oldest item so that the length never
> goes above 'n'. (Its for caching search results)
import collections
class Cache(dict):
def __init__(self, n, *args, **kwds):
not clear if you want a FIFO, or a LRU on read or write, so for the
non-dictionary component of this, you could also ( (search Cookbook)
|| google) for terms like "ring buffer", "fixed-size cache", um,
"bounded queue", "circular buffer", "deque", there's probably a bunch
of others.
--
http://mai
Will McGugan wrote:
> I need a collection class that behaves like a dictionary but when it
> reaches 'n' items it discards the oldest item so that the length never
> goes above 'n'. (Its for caching search results)
>
> I have a vague memory of a module that does this, but I cant remember
> whe
Hi folks,
I need a collection class that behaves like a dictionary but when it
reaches 'n' items it discards the oldest item so that the length never
goes above 'n'. (Its for caching search results)
I have a vague memory of a module that does this, but I cant remember
where I read about it. Ca
11 matches
Mail list logo