lru od
0.0.1
OrderedDict 사용하여 LRU 캐시의 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 으로 새/기존 키 값 쌍을 설정/업데이트하고 만들/업데이트 된 키 값 쌍을 반환합니다.