def __init__(self, cache_dir=None, expiration_in_minutes=30):
# Protects |self| but individual file objects in |store| are not
# protected once its returned from |_file_for|.
self.lock = threading.Lock()
# Dictionary mapping a URL to a tuple containing a file object and a
# timestamp. The timestamp notes the creation time.
self.store = {}
# Directory containing cache files. If |cache_dir| is None, then each
# file is created independently using tempfile.TemporaryFile().
self.cache_dir = cache_dir
# Garbage collector timer.
self.timer = threading.Timer(15 * 60, self.gc)
self.timer.start()
self.expiration = datetime.timedelta(minutes=expiration_in_minutes)
if cache_dir and not os.path.exists(cache_dir):
if not os.path.isabs(cache_dir):
raise ValueError('|cache_dir| should be an absolute path')
os.mkdirs(cache_dir)
评论列表
文章目录