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返回創建/更新的鍵值對