Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
tkem committed Nov 30, 2018
1 parent e5641ed commit 5e29f42
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions cachetools/ttl.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,13 @@ def __iter__(self):
curr = iter(self.__expire.items())
# "freeze" time for iterator access
with self.__timer as time:
while True:
key, expire = next(curr)
if not (expire < time):
yield key
try:
while True:
key, expire = next(curr)
if not (expire < time):
yield key
except StopIteration:
pass

def __len__(self):
time = self.__timer()
Expand Down Expand Up @@ -131,13 +134,16 @@ def expire(self, time=None):
if time is None:
time = self.__timer()
cache_delitem = Cache.__delitem__
while True:
key, expire = next(iter(self.__expire.items()), (None, time))
if not (expire < time):
break
cache_delitem(self, key)
del self.__order[key]
del self.__expire[key]
try:
while True:
key, expire = next(iter(self.__expire.items()), (None, time))
if not (expire < time):
break
cache_delitem(self, key)
del self.__order[key]
del self.__expire[key]
except StopIteration:
pass

def clear(self):
with self.__timer as time:
Expand Down

0 comments on commit 5e29f42

Please sign in to comment.