博客 / 詳情

返回

Python 函數緩存(qbit)

前言

  • 本文的 Python 3.8 適用
  • 截至 2021.4.14,functools.lru_cachecachetools 都不支持異步函數的緩存(async

functools.lru_cache

  • 官方標準庫: functools.lru_cache
  • lru_cache 增加生命週期管理: https://stackoverflow.com/que...

cachetools

  • pypi: https://pypi.org/project/cach...
  • github: https://github.com/tkem/cache...
  • 文檔: https://cachetools.readthedoc...
  • cachetools v4.2.1 已實現緩存機制

    FIFO: First In First Out,先進先出
    LFU:  Least Frequently Used,最小頻率使用,淘汰一段時間內使用次數最少的
    LRU:  Least Recently Used,最近最少使用,淘汰最長時間沒有被使用的
    MRU:  Most Recently Used,(淘汰)最近最多使用
    RR:   Random Replacement,隨機替換
    TTL:  time-to-live,每個條目按生存時間淘汰
qbit snap
user avatar u_16213589 頭像
1 位用戶收藏了這個故事!

發佈 評論

Some HTML is okay.