lru od
0.0.1
OrderedDictを使用したLRU-CacheのPython実装
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
keyでキー値ペアの値を取得しますkeyパラメーターに関連付けられたキー価値ペアを削除しますkeyとpairを使用して新しい/既存のキー値ペアを設定/更新し、作成/更新されたキー値ペアを返します