Skip to content

[deprecated] design_of_renrenCache

JackonYang edited this page Jan 12, 2013 · 1 revision

废弃。 原因:暂时主要在parser中使用,意义较小,复杂性太高。
parser解析内容包括 friendlist 页面的 friendlist和names,profile页面的详细资料内容。
其中,friendlist,重构后每次解析一个用户的完整列表,平均 200-300条好友关系,200-300好友姓名。无需缓存,可直接插入db。
profile页面为了防止被封,每次解析后都需sleep n sec,频繁db读写操作不影响效率。缓存却增加空间消耗。

需求分析

原始需求

  1. 缓存数据(buffer),作为功能代码与存储介质的桥梁,减少I/O操作。
  2. 集中管理内存中的活跃数据,增加数据安全和稳定性

人人网数据分析

人人网的数据可以用3个维度唯一标识:renrenId,attribute,value.
例如:renrenId=234234, attribute=name, value=Tom

使用场景:

  1. 数据解析时,单一页面可能解析出多个字段,难以用返回值方便的进行参数传递。
    直接I/O操作效率低,直接扔入内存不适合于大规模数据,且数据种类较多时,容易导致混乱。 解决方案,将解析出的字段直接写入renrenCache。

设计方案

数据管理

  1. 人人数据存储。
    由一个大 dict 集中管理全部数据。
    key-value 分别是 attibute-subDicit, subDict 的key-value 为 renrenId-value

  2. 索引。
    TODO

接口(public method)

  1. 数据插入
    addItem(attr,renrenId,value): 插入单条数据。
    addItems(attr,itemsDict): 插入特定 attr 的多条数据,数据为 renrenId-value 的dict形式。
  2. 数据读取
    getValue(attr=None,renrenId=None,value=None):
    getAttrData()
  3. 加载与永久保存
    load 从文件或数据库加载数据。
    save 数据写入文件或数据库。
  4. attribute 管理
    initAttr(attr=None): 初始化attr
    addAttr(attr): 插入attr
    getAttr(): 获取attr集合