转自:https://blog.csdn.net/sinat_26918145/article/details/71215711,https://www.cnblogs.com/liang24/p/14208977.html
1.key值
针对getAll,getRow,获取全部,获取某一行,缓存key命名:
//针对 getAll: db_name:table_name:all:others:sql_hash //针对 getRow: db_name:table_name:row:primary_key_id=?
//getAll是获取结果集?
- 在 update ,delete, insert 之后都会全部清除 db_name:table_name:all:others:* 的缓存,并且根据修改的 id 去清除 db_name:table_name:row:primary_key_id=? 里面的行缓存 。
- 在 insert 之后就单单增加 db_name:table_name:row:primary_key_id=? 的缓存。
即增删改时,既要更新getAll也要更新对应的getRow。
查询缓存例子:
String cacheKey = “productid_11010003”; String cacheValue = redisCache.get(cacheKey); //缓存命中 if ( cacheValue != NULL) return cacheValue; //缓存缺失 else cacheValue = getProductFromDB(); redisCache.put(cacheValue) //缓存更新