lru od
0.0.1
使用OrderedDict实施LRU-CACHE
Python 3.7或更高要求!
要安装库的稳定版本:
# on linux/macOS
python3 -m pip install lru-od
# windows
py -3 -m pip install lru-od安装库的开发版本:
$ git clone https://github.com/XiehCanCode/lru-od
$ cd lru-od
$ python3 -m pip install -U . from lru import LRUCache
cache : LRUCache [ str , str ] = LRUCache ( max_size = 2 )
cache . set ( "foo" , "bar" ) # you can also use: cache['foo'] = 'bar'
cache . set ( "bar" , "foo" )
print ( cache . get ( "foo" )) # this key-pair would be pushed to end
cache . set ( "ping" , "pong" ) # since we're exceeding the max size, the least used will be removed, in this case it's {'bar': 'foo'} 类Lrucache
LRU缓存实现
max_size:可选[ int ]
缓存的最大大小,默认为120
x == y
x != y
x in y
keykey参数关联的密钥值对key新/现有键值对,然后pair返回创建/更新的键值对