查询优化的一些经验
2016-04-28 11:39
281 查看
1、加缓存
2、list里面需要组装不同的bean,这些bean需要分别查询数据库或缓存,可以查询完之后,建一个5分钟的缓存,下次查,直接从缓存中取
3、读写分离
http://lvwenwen.iteye.com/blog/1486939
4、tomcat数据源jndi
2、list里面需要组装不同的bean,这些bean需要分别查询数据库或缓存,可以查询完之后,建一个5分钟的缓存,下次查,直接从缓存中取
3、读写分离
http://lvwenwen.iteye.com/blog/1486939
4、tomcat数据源jndi
package com.moji.article.web.pattern; import java.sql.Date; import java.util.ArrayList; import java.util.List; import com.moji.article.service.ArticleService; import com.moji.article.service.ArticleStatService; import com.moji.article.web.pattern.ArticleDetailResBean.ArticleResBean; import com.moji.sns.common.constant.article.ArticleMemcachePoolValues; import com.moji.util.common.LocaleUtil; public class ArticleListByIdsStrategyImpl implements ArticleListByIdsStrategy { private ArticleDetailStrategy articleDetailStrategy; private ArticleService articleService; @Override public ArticleListByIdsResBean listByIds(ArticleListByIdsReqForm form) { ArticleListByIdsResBean resBean = new ArticleListByIdsResBean(); resBean.setCode(0); List<Long> articleIdList = form.getParams().getArticle_id_list(); Integer lanId = Integer.parseInt(LocaleUtil.getLocaleByLanguageKey(form .getCommon().getLanguage())); Long snsId = form.getCommon().getSnsid(); // 查5分钟缓存的memCache是否存在 List<ArticleDetailResBean.ArticleResBean> articleBeanList = getFromMem(); if (articleBeanList != null) { resBean.setArticle_list(articleBeanList); return resBean; } articleBeanList = new ArrayList<ArticleDetailResBean.ArticleResBean>(); for (Long articleId : articleIdList) { ArticleDetailResBean.ArticleResBean articleBean = articleDetailStrategy .format(articleId, lanId, snsId); if (articleBean != null && articleBean.getDel_status().intValue() == ArticleStatService.STAT_NOT_DEL .intValue()) { articleBeanList.add(articleBean); } } // 存5分钟缓存 setToMem(articleBeanList); resBean.setArticle_list(articleBeanList); return resBean; } private void setToMem(List<ArticleDetailResBean.ArticleResBean> articleBeanList){ articleService.setBeanToMem( ArticleListByIdsStrategy.ARTICLE_DEATIL_RES_BEAN_KEY, ArticleMemcachePoolValues.LATEST_MEMCACHE_POOL_ARTICLE, articleBeanList, new Date(1000 * 60 * 5)); } private List<ArticleDetailResBean.ArticleResBean> getFromMem(){ @SuppressWarnings("unchecked") List<ArticleDetailResBean.ArticleResBean> articleBeanList = (List<ArticleResBean>) articleService .getBeanFormMemcache( ArticleListByIdsStrategy.ARTICLE_DEATIL_RES_BEAN_KEY, ArticleMemcachePoolValues.LATEST_MEMCACHE_POOL_ARTICLE, List.class); return articleBeanList; } public void setArticleService(ArticleService articleService) { this.articleService = articleService; } public void setArticleDetailStrategy( ArticleDetailStrategy articleDetailStrategy) { this.articleDetailStrategy = articleDetailStrategy; } }
相关文章推荐
- 计算机是如何启动的?
- Css中position、float和clear整理
- hdu 1010 Tempter of the Bone
- cmd 命令行方式执行 matlab 脚本
- morgan中间件记录日志
- window系统查看端口被哪个进程占用了
- 程序员才能看得懂的内涵段子
- 我们为什么还要sim卡
- runtime的几种技术
- iOS常用插件
- ASP.NET WEBFORM 中导出数据,使用文件流的方式
- ios 上下拉刷新
- 62. Unique Paths && 63. Unique Paths II
- HTTP Live Streaming直播(iOS直播)技术分析与实现
- google network面板用法详解
- SICP EX1-9 change 问题
- python3抓取到的拉勾数据统计
- CentOS7执行ifconfig Command not found 未找到命令
- Java中的微信公众号开发(一)
- php 中 array_map的使用