file_cache.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:ChromiumXRefs 作者: karlinjf 项目源码 文件源码
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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号