关于新闻缓存设计

使用FMDB进行缓存设计

分析:

新闻相关列表相关参数:

"id": "1447",
"title": "2015思埠梦想盛典进入倒计时 见证荣耀时刻",
"public_time": "2015.01.20",
"cover_small": "http://img.sibu.cn/uploads/1501/327-1421718905-150_phone.jpg",
"cover_big": "http://img.sibu.cn/uploads/allimg/1501/22-150120095I22P.jpg",
"like": "1432",
"comment": "290"

每条新闻都有一个唯一的ID

缓存新闻步骤

一).1.根据新闻ID查询数据库中是否包含了此条新闻

"select *from newsTable where newsID = %ld"

二). 1.当新闻id不在数据库中,则将其保存

  2.当新闻存在数据库中,则将其更新(新闻内容可能有变化)

NSString *sql = @"insert into User (newsID, content) values (?, ?)";
[db executeUpdate:sql, model.id, model.content];

高阶

1.查询固定数量新闻

2.存储固定数量新闻

 

 

 

 

 

 

原文地址:https://www.cnblogs.com/sixindev/p/4636022.html