鲲鹏网页缓存库:KPCache

jopen 10年前

鲲鹏网页缓存库(Python) - KPCache    特性:  无需后端数据库,直接操作文件系统(建议使用Ext4文件系统),速度快。  基于ZMQ通信,支持网络高速存取。  支持多线程。  支持服务端掉线自动重连。  支持多种缓存数据类型(所有能被Python pickle的类型均被支持,不限于字符串)。  完全兼容webscraping库。    实测速度:  存储100万文档(单个大小为6.5KB)用时约1000秒。测试脚本:test.py。    安装依赖库ZMQ:  sudo easy_install zmq    启动服务端:  >>> from KPCache import KPCache  >>> KPCache.KPCacheServer(server_host='127.0.0.1', server_port=8080, folder='.KPCache').run_server()  The cache server is running on 127.0.0.1:8080, cache data will be saved in .KPCache    server_host - 服务端监听的地址,默认是127.0.0.1,如果想远程使用,可以设置为0.0.0.0。  server_port - 服务端监听的端口,默认是8080。  folder - 缓存数据的存储目录,默认是.KPCache目录。      客户端使用举例:  >>> from KPCache import KPCache  >>> cache = KPCache.KPCacheClient(server_host='127.0.0.1', server_port=8080)  >>>   >>> cache['name'] = 'Qi' # 测试保存一个字符串  >>> print cache['name']  # 测试读取  Qi  >>>   >>> cache['dict'] = {'website': 'http://www.site-digger'} # 测试保存一个字典类型数据  >>> print cache['dict']  {'website': 'http://www.site-digger'}  >>>   >>> from datetime import datetime  >>> cache['date_time'] = datetime.now() # 测试保存一个时间日期类型的数据  >>> print cache['date_time']  2014-01-23 18:34:15.921058  >>>  >>> del cache['dict'] # 测试删除某个缓存  >>> print cache['dict'] # 读取不存在的缓存会抛出 KeyError异常  Traceback (most recent call last):    File "<stdin>", line 1, in <module>    File "KPCache/KPCache.py", line 58, in __getitem__      raise KeyError('%s does not exist' % key)  KeyError: 'dict does not exist'  >>>   >>> 'http://www.site-digger.com' in cache # 判断一个key是否在缓存中  False  >>> 'name' in cache  True    注意:  在多线程中使用时,每个线程需要建立各自客户端实例,不能共享同一个客户端实例。
https://bitbucket.org/qi/kpcache/overview