Cache缓存优化
降低数据库压力
<appSettings><add key="ModelCache" value=""/></appSettings> //设置实体缓存时间 public RupengWang.Model.Course GetModelByCache(long Id)
{
string CacheKey = "CourseModel-" + Id;
object objModel = Maticsoft.Common.DataCache.GetCache(CacheKey);
if (objModel == null)
{
objModel = dal.GetModel(Id);
if (objModel != null)
{
int ModelCache = Maticsoft.Common.ConfigHelper.GetConfigInt("ModelCache");
Maticsoft.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
}
}
return (RupengWang.Model.Course)objModel;
}
2.MVC中缓存
/// <summary>
/// 从缓存中获得自定义匿名对象
/// </summary>
/// <returns></returns>
public object GetModelByCache()
{
string CacheKey = "MyProductAndGroupModel_";
object objModel = HttpRuntime.Cache[CacheKey]; //获得当前应用程序的缓存
if (objModel == null)
{
objModel = GetDefineModelByEdm();
if (objModel != null)
{
//int ModelCache = Convert.ToInt32(ConfigurationManager.AppSettings["ModelCache"]);
HttpRuntime.Cache.Insert(CacheKey, objModel, null, DateTime.Now.AddMinutes(), TimeSpan.Zero);
}
}
return objModel;
}
3 WebForm中所写最简单的缓存:
public partial class WebForm_cache : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
#region 缓存
List<object> list = (List<object>)HttpRuntime.Cache["tc_students"];
if (list == null || list.Count <= ) //如果缓存中没有就从DB中获取
{
List<object> listDB = new MyORM_BLL().SelectAllModel(typeof(TC_STUDENT));
if (listDB.Count > ) //把数据库中获得的数据进行缓存
{
HttpRuntime.Cache.Insert("tc_students", listDB, null, DateTime.Now.AddSeconds(), TimeSpan.Zero);
}
list = listDB;
}
Repeater1.DataSource = list;
Repeater1.DataBind();
#endregion
}
} WebForm_cache.aspx.cs
参考:
http://www.cnblogs.com/zgx/archive/2009/03/16/1413643.html
http://bbs.csdn.net/topics/310107146
Cache缓存优化的更多相关文章
- django缓存优化中caches参数如何配置?
在python开发中,如果运营django进行编写,为了提升效率,常常需要优化缓存,缓存优化中必须掌握的caches参数相关知识: CACHES 配置参数概述 - 格式 CACHES 字典配置格式如下 ...
- PHP服务缓存优化之ZendOpcache、xcache、eAccelerator
PHP服务缓存优化原理 Nginx 根据扩展名或者过滤规则将PHP程序请求传递给解析PHP的FCGI,也就是php-fpm进程 缓存操作码(opcode) Opcode,PHP编译后的中间文件,缓存给 ...
- 注释驱动的 Spring cache 缓存介绍
概述 Spring 3.1 引入了激动人心的基于注释(annotation)的缓存(cache)技术,它本质上不是一个具体的缓存实现方案(例如 EHCache 或者 OSCache),而是一个对缓存使 ...
- [转]注释驱动的 Spring cache 缓存介绍
原文:http://www.ibm.com/developerworks/cn/opensource/os-cn-spring-cache/ 概述 Spring 3.1 引入了激动人心的基于注释(an ...
- iOS网络加载图片缓存策略之ASIDownloadCache缓存优化
iOS网络加载图片缓存策略之ASIDownloadCache缓存优化 在我们实际工程中,很多情况需要从网络上加载图片,然后将图片在imageview中显示出来,但每次都要从网络上请求,会严重影响用 ...
- 注释驱动的 Spring cache 缓存介绍--转载
概述 Spring 3.1 引入了激动人心的基于注释(annotation)的缓存(cache)技术,它本质上不是一个具体的缓存实现方案(例如 EHCache 或者 OSCache),而是一个对缓存使 ...
- MySQL优化二(连接优化和缓存优化)
body { font-family: Helvetica, arial, sans-serif; font-size: 14px; line-height: 1.6; padding-top: 10 ...
- MySQL优化-一 、缓存优化
body { font-family: Helvetica, arial, sans-serif; font-size: 14px; line-height: 1.6; padding-top: 10 ...
- Java系统高并发之Redis后端缓存优化
一:前端优化 暴露接口,按钮防重复(点击一次按钮后就变成禁用,禁止重复提交) 采用CDN存储静态化的页面和一些静态资源(css,js等) 二:Redis后端缓存优化 Redis 是完全开源免费的,遵守 ...
随机推荐
- leetcode刷题3.无重复字符的最长子串
题目:给定一个字符串,找出不含有重复字符的 最长子串 的长度. 示例: 给定 "abcabcbb" ,没有重复字符的最长子串是 "abc" ,那么长度就是3. ...
- tcp三次握手过程
TCP握手协议 在TCP/IP协议中,TCP协议提供可靠的连接服务,采用三次握手建立一个连接.第一次握手:建立连接时,客户端发送syn包(syn=j)到服务器,并进入SYN_SEND状态,等待服务器确 ...
- json前后台传输,以及乱码中文问题探讨
背景介绍: 我现在的工作是做传统项目开发,没有用到框架.最近在做项目时,经常需要使用ajax从后台拿数据到前台,是json格式的.先说下我在项目中遇到的问题吧,前台拿到了数据,需要将其转化为对象,我使 ...
- linux 查看各目录(文件夹)下文件大小
# 显示总大小(/下全部文件占用大小) du -sh /* | sort -nr # 显示各文件夹的大小(当前文件夹下各文件夹的大小) du --max-depth=1
- 按F12 IE浏览器的开发工具打不开解决方法
在电脑的任务栏中选中开发人员工具窗体右击,出现以下页面: 点击移动菜单项,然后用键盘的上下左右键移动,直到开发人员工具的最小化窗体出现:
- YARN中的失败分析
YARN中的失败分析 对于在YARN中运行的MapReduce程序,需要考虑以下几种实体的失败任务.application master.节点管理器.资源管理器 1. 任务运行失败 任务运行失败类似于 ...
- yarn作业提交过程源码
记录源码细节,内部有中文注释 Client 端: //最终通过ApplicationClientProtocol协议提交到RM端的ClientRMService内 package org.apache ...
- linux中动态链接库的创建与使用
LINUX系统中动态链接库的创建与使用 http://www.cnblogs.com/ardar/articles/357321.html 正常C源文件编写,编译时-shared即可得到SO, gcc ...
- WinDBG__独立安装文件
debugging tools for windows 1. 来自于网页:http://rxwen.blogspot.hk/2010/04/standalone-windbg-v6120002633. ...
- 一个简单客户端获取IP,国家,城市,省份的代码
<html><head> <script src="js/jquery-1.6.2.min.js" type="text/javascri ...