Skip to content

Instantly share code, notes, and snippets.

@arlolra arlolra/
Created Apr 11, 2013

What would you like to do?
#!/usr/bin/env python
# requires python >= 2.7
# see:
from collections import OrderedDict
MAXLRU = 200
class LRU(OrderedDict):
def __init__(self, *args, **kwds):
self.size = kwds.pop("size", MAXLRU)
OrderedDict.__init__(self, *args, **kwds)
def __setitem__(self, key, value):
if key in self:
del self[key]
OrderedDict.__setitem__(self, key, value)
def limit(self):
while len(self) > self.size:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.