Source

ferrybox / dumb_memcache.py

Full commit
import time

data = {}
timeouts = {}

def get(key):
    if key in timeouts and timeouts[key] > time.time():
        del timeouts[key]
        if key in data:
            del data[key]
        return None
    return data.get(key, None)

def add(key, value, timeout=None):
    if timeout:
        timeouts[key] = time.time() + timeout
    data[key] = value

def flush_all():
    data.clear()