Self reordering list in Python

Fredrik Lundh fredrik at pythonware.com
Fri Sep 16 12:38:58 EDT 2005


Terry Hancock wrote:

> This is actually the use-case for an "LRU cache"="least recently used
> cache", which is probably already implemented in Python somewhere (or
> even as a fast extension).  I'd do a google search for it.

reposted, in case there are more people who cannot be bothered
to read other replies before posting:

    http://www.python.org/pypi/lrucache/0.2

(it's a straight-forward and rather flexible implementation, which uses
a dictionary to quickly find existing objects, and a heap to keep track
of access times.  if you have more control over the stuff that goes into
the cache, you can strip things down to 10-20 lines of code and code
it in about the same time it took me to write this post)

</F> 






More information about the Python-list mailing list