Just a minor comment: insert(0) is an expensive (O(N))
> operation on lists. This kind of problem might be better
> addressed with a deque
> could be backported to py2.3).
If I read the patch correctly, usage_stack is being used as a simple
I think the data structure we want is a class derived from dict that
pops elements off (preferably intelligently, ie pops the ones which
haven't been accessed in a while) when the dict length gets too long.
In other words, we don't need to structures (cached and usage_stack)
to do the work of one
There must be such a beast in the cookbook or elsewhere, a cache
object which works like a dict but has a max size...