lru od
0.0.1
การใช้ Python ของ LRU-cache โดยใช้ OrderedDict
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 และส่งคืนคู่คีย์-ค่าที่สร้างขึ้น/อัปเดต