dictionary that discards old items

Tim Williams (gmail) tdwdotnet at gmail.com
Fri Jul 22 07:02:39 EDT 2005


On 7/21/05, Michael Hoffman <cam.ac.uk at mh391.invalid> 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 this, but I cant remember
> > where I read about it. Can anyone enlighten me?
> 
> You want a Least Recently Used, or LRU, cache. Here's one:
> 
> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/252524
> 

http://py.vaults.ca/apyllo.py/514463245.769244789.92554878



More information about the Python-list mailing list