Skip to content
Snippets Groups Projects
Commit 627d0efb authored by Paul McCarthy's avatar Paul McCarthy
Browse files

Little adjustements to Cache class

parent a22d6683
No related branches found
No related tags found
No related merge requests found
...@@ -63,7 +63,8 @@ class Cache(object): ...@@ -63,7 +63,8 @@ class Cache(object):
``0`` will not expire. ``0`` will not expire.
""" """
if len(self.__cache) == self.__maxsize: if len(self.__cache) == self.__maxsize and \
key not in self.__cache:
self.__cache.popitem(last=False) self.__cache.popitem(last=False)
self.__cache[key] = CacheItem(key, value, expiry) self.__cache[key] = CacheItem(key, value, expiry)
...@@ -105,11 +106,15 @@ class Cache(object): ...@@ -105,11 +106,15 @@ class Cache(object):
def clear(self): def clear(self):
"""Remove all items fromthe cache. """Remove all items from the cache. """
"""
self.__cache = collections.OrderedDict() self.__cache = collections.OrderedDict()
def __len__(self):
"""Returns the number of items in the cache. """
return len(self.__cache)
def __parseDefault(self, *args, **kwargs): def __parseDefault(self, *args, **kwargs):
"""Used by the :meth:`get` method. Parses the ``default`` argument, """Used by the :meth:`get` method. Parses the ``default`` argument,
which may be specified as either a positional or keyword argumnet. which may be specified as either a positional or keyword argumnet.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment