前言
cachetools 是一个 Python 模块,提供各种记忆集合和修饰符,包括 Python 3 标准库的 @lru_cache 函数修饰符。
>>> from cachetools import LRUCache>>> cache = LRUCache(maxsize=2)>>> cache.update([('first', 1), ('second', 2)])>>> cache LRUCache([('second', 2), ('first', 1)], maxsize=2, currsize=2)>>> cache['third'] = 3>>> cache LRUCache([('second', 2), ('third', 3)], maxsize=2, currsize=2)>>> cache['second']2>>> cache['fourth'] = 4>>> cache LRUCache([('second', 2), ('fourth', 4)], maxsize=2, currsize=2)