1. What web caching means and includes
2. Why use caching
3. File caching
4. Share caching
5. Local caching
6. Memcached and its usage
7. TTServer and KTServer
8. Redis VS SSDB
9. CDN cachings
10. Twemproxy
11. Programming skills and tips
25. 应用(二)
-- Nginx 共享内存字典模块: lua_shared_dict
-- 缓存黑词
local badwords
local lcache = ngx.shared['lcache']
if lcache then
badwords = lcache:get(‘KEY_BADWORDS’)
end
if not badwords then
local hc = self:_getHttpObj()
badwords = hc:get('api.xxx.com', '/API/black_word')
if badwords then
lcache:set(‘KEY_BADWORDS’, badwords, 600)
end
end
46. 应用(四)
-- 利用 hmset 实现实时记录最新更新的表:
local rhkey = 'tb|updates'
local hData = {}
hData[tableIndex] = cjson.encode(currentTime)
rds:hmset(rhkey, hData)
……
local tableRecords = rds:hgetall($rhkey);
if tableRecords then
.......
end
47. 应用(五)
-- 使用 hmget / hmset 实现正确的分页缓存
-- 清理所有分页:rds:hclear(hlkey)
local list
local hlkey = 'hashlist|' .. vid
local hlfield = orderby .. '|' .. num
local hResult = rds:hmget(hlkey, hlfield)
if hResult and hResult[1] then
list = cjson.decode(hResult[1])
else
list = self:_getList(vid, orderby, num)
local hData = {}
hData[hlfield] = cjson.encode(list)
rds:hmset(hlkey, hData)
end
63. 应用
local res = db:findOne(sql)
if type(res) == 'table' and res['id'] then
rds:setex(key, cjson.encode(res), 3600)
elseif db.lasterr == db.ERROR_NOT_FOUND then
rds:setex(key, cjson.encode(res), 60)
else
-- 查询异常或者查询超时等情况
end