最近使用最少的缓存算法(lru)的简单实现
lru_p的Python项目详细描述
最近使用最少的缓存算法的简单python实现。
你好,世界
lru的简单用法:
from lru_py import LRU lru_cache = LRU(max_size = 2) lru_cache['hello'] = 'world' lru_cache['world'] = 'hello' lru_cache['hello'] = 'world' print "The first item now is: " + lru_cache.top() print "The value of the key 'world' now is: " + lru_cache['world'] print "The first item now after retrieving the key 'world' is: " +lru_cache.top()
如何:
初始化对象:
lru_cache = LRU(max_size = 2)
设置值,使用方括号运算符进行常规赋值[]:
lru_cache[‘hello’] = ‘world’
使用方括号运算符[]检索值:
lru_cache[‘hello’]
deletin,使用del和方括号运算符:
del lru_cache[‘hello’]
检索最近使用的项目:
lru_cache.top()
安装
自动安装:
pip install lru_py
手动安装:从GitHub下载最新的源代码。
tar xvzf lru_py-[VERSION].tar.gz cd lru_py-[VERSION] python setup.py build sudo python setup.py install