def basic_cleanup(self):
next_expire = None<EOL>keys_to_delete = []<EOL>if self.expire is not None and self.expire > <NUM_LIT:0>:<EOL><INDENT>for k, item in self.cache_items.items():<EOL><INDENT>if item.is_dead():<EOL><INDENT>keys_to_delete.append(k)<EOL><DEDENT>else:<EOL><INDENT>next_expire = item.remaining_survival_time()<EOL>break<EOL><DEDENT><DEDENT><DEDENT>for k in keys_to_delete:<EOL><INDENT>self.cache_items.pop(k)<EOL><DEDENT>while (len(self.cache_items) > self.capacity):<EOL><INDENT>evicted_keys = self.evict_func(cache_dict=self.cache_items, evict_number=self.evict_number)<EOL>self.logger.debug('<STR_LIT>' % (len(evicted_keys), evicted_keys))<EOL><DEDENT>return next_expire<EOL>
Test:

>>> from common_cache import Cache
>>> import time
>>> cache = Cache(expire=1, cleanup_func=basic_cleanup, regularly_cleanup=False)
>>> cache.put('a', value=0)
>>> cache.put('b', value=1)
>>> cache.put('c', value=2)
>>> cache.put('d', value=3, expire=3)
>>> cache.size()
4
>>> time.sleep(1)
>>> cache.put('e', 4)
>>> cache.get('a') == None
True
>>> cache.get('d') == None
False