'''
MiniFridge is a dict-like class with optional self-destruct timers.
CacheOutput is a decorator which caches outputs of function calls.
'''

import datetime as dt
from threading import Lock


class MiniFridge(object):
    
    '''
    A MiniFridge is like a dictionary, but with 2 extra rules:
    
    1. If another thread is using the fridge, then wait your turn.
    2. If you see something past its expiration date, then throw it out.
    
    Some MiniFridge methods allow users to set a countdown timer.
    These timers are set using keyword arguments for datetime.timedelta:
    weeks, days, hours, minutes, seconds, microseconds, milliseconds
    
    Examples:
    
    mf = MiniFridge(minutes=1)      # Make a MiniFridge with 1-minute timer
    
    mf.put('spam',42,expire=False)  # Put spam in mf. It never expires
    mf.put('eggs',2,seconds=2)      # Put eggs in mf. It expires in 2 seconds.
    mf['beer'] = 100                # Put beer in mf. It expires in 1 minute.
    
    mf['spam']                      # Get value for key 'spam'
    mf.get('eggs',default='Nope')   # Get value without raising KeyError if key is bad
    mf.pop('beer',default=None)     # Pop value without raising KeyError if key is bad
    
    mf.keys()                       # Delete any bad items. Return the good keys.
    mf.purge()                      # Delete any expired (key,value) pairs