|
|
@@ -13,6 +13,22 @@ class TagCache: |
|
|
|
self._count = count |
|
|
|
self._modified = False |
|
|
|
|
|
|
|
def _limit_count(self): |
|
|
|
while len(self._cache) > self._count: |
|
|
|
del self._cache[next(iter(self._cache.keys()))] |
|
|
|
|
|
|
|
@property |
|
|
|
def count(self): |
|
|
|
'''The number of items allowed in the cache.''' |
|
|
|
|
|
|
|
return self._count |
|
|
|
|
|
|
|
@count.setter |
|
|
|
def count(self, v): |
|
|
|
self._count = v |
|
|
|
|
|
|
|
self._limit_count() |
|
|
|
|
|
|
|
@property |
|
|
|
def modified(self): |
|
|
|
'''Return if the cache has been modified since the last |
|
|
@@ -33,8 +49,7 @@ class TagCache: |
|
|
|
|
|
|
|
self._cache[tag] = None |
|
|
|
|
|
|
|
while len(self._cache) > self._count: |
|
|
|
del self._cache[next(iter(self._cache.keys()))] |
|
|
|
self._limit_count() |
|
|
|
|
|
|
|
def tags(self): |
|
|
|
'''Returns the sorted list of tags in the cache.''' |
|
|
@@ -119,3 +134,16 @@ class _TestTagCache(unittest.TestCase): |
|
|
|
|
|
|
|
self.assertEqual(ntc.tags(), [ ('foo', 'foo'), ('whee', 'whee') ]) |
|
|
|
|
|
|
|
ntc.count = 3 |
|
|
|
|
|
|
|
ntc.add(('a', 'a')) |
|
|
|
|
|
|
|
ntc.add(('b', 'b')) |
|
|
|
|
|
|
|
self.assertEqual(ntc.tags(), [ ('a', 'a'), ('b', 'b'), ('whee', 'whee') ]) |
|
|
|
|
|
|
|
ntc.add(('whee', 'whee')) |
|
|
|
|
|
|
|
ntc.count = 2 |
|
|
|
|
|
|
|
self.assertEqual(ntc.tags(), [ ('b', 'b'), ('whee', 'whee') ]) |