降低数据库压力
<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缓存优化的更多相关文章

  1. django缓存优化中caches参数如何配置?

    在python开发中,如果运营django进行编写,为了提升效率,常常需要优化缓存,缓存优化中必须掌握的caches参数相关知识: CACHES 配置参数概述 - 格式 CACHES 字典配置格式如下 ...

  2. PHP服务缓存优化之ZendOpcache、xcache、eAccelerator

    PHP服务缓存优化原理 Nginx 根据扩展名或者过滤规则将PHP程序请求传递给解析PHP的FCGI,也就是php-fpm进程 缓存操作码(opcode) Opcode,PHP编译后的中间文件,缓存给 ...

  3. 注释驱动的 Spring cache 缓存介绍

    概述 Spring 3.1 引入了激动人心的基于注释(annotation)的缓存(cache)技术,它本质上不是一个具体的缓存实现方案(例如 EHCache 或者 OSCache),而是一个对缓存使 ...

  4. [转]注释驱动的 Spring cache 缓存介绍

    原文:http://www.ibm.com/developerworks/cn/opensource/os-cn-spring-cache/ 概述 Spring 3.1 引入了激动人心的基于注释(an ...

  5. iOS网络加载图片缓存策略之ASIDownloadCache缓存优化

    iOS网络加载图片缓存策略之ASIDownloadCache缓存优化   在我们实际工程中,很多情况需要从网络上加载图片,然后将图片在imageview中显示出来,但每次都要从网络上请求,会严重影响用 ...

  6. 注释驱动的 Spring cache 缓存介绍--转载

    概述 Spring 3.1 引入了激动人心的基于注释(annotation)的缓存(cache)技术,它本质上不是一个具体的缓存实现方案(例如 EHCache 或者 OSCache),而是一个对缓存使 ...

  7. MySQL优化二(连接优化和缓存优化)

    body { font-family: Helvetica, arial, sans-serif; font-size: 14px; line-height: 1.6; padding-top: 10 ...

  8. MySQL优化-一 、缓存优化

    body { font-family: Helvetica, arial, sans-serif; font-size: 14px; line-height: 1.6; padding-top: 10 ...

  9. Java系统高并发之Redis后端缓存优化

    一:前端优化 暴露接口,按钮防重复(点击一次按钮后就变成禁用,禁止重复提交) 采用CDN存储静态化的页面和一些静态资源(css,js等) 二:Redis后端缓存优化 Redis 是完全开源免费的,遵守 ...

随机推荐

  1. jQuery计算器插件

    在线演示 本地下载

  2. INDEL的重新比对和碱基质量分数的重新校准

    1.为什么要做这两步(why): indel的重新比对:这是由于比对软件的自身限制,其可能将包括indel的read解释为snp的read,这就导致calling的错误和后面的碱基质量分数的重新校准. ...

  3. 转载:ensemble计划和数据库

    原文来源:x2yline在生信进化树上的评论,http://www.biotrainee.com/thread-626-1-1.html Ensemble( ensembl.org网站是常用真核生物参 ...

  4. CSS3的transform属性

    CSS3的一些属性可能比较新,有一些书从国外翻译到国内的时间上会延缓1-2年.所以有一些东西还需要及时整理. 下面说一下CSS3的一个属性:transform 其实字面上的意思已经很明显了就是变化,变 ...

  5. 3Sum,4Sum问题

    //三数和为0的问题.要求去重,并且输出数字有序.public List<List<Integer>> threeSum(int[] nums) { Arrays.sort(n ...

  6. UOJ14 DZY Loves Graph

    DZY开始有 nn 个点,现在他对这 nn 个点进行了 mm 次操作,对于第 ii 个操作(从 11 开始编号)有可能的三种情况: Add a b: 表示在 aa 与 bb 之间连了一条长度为 ii ...

  7. hdoj1006--Tick and Tick

    Problem Description The three hands of the clock are rotating every second and meeting each other ma ...

  8. windows7下cmd窗口使用ssh命令

    http://jingyan.baidu.com/article/36d6ed1f931eb31bcf4883dc.html

  9. s3cmd 安装使用指南

    https://wangyan.org/blog/s3cmd-how-to-use.html s3cmd 安装使用指南 s3cmd 是一款 Amazon S3 命令行工具.它不仅能上传.下载.同步,还 ...

  10. ie-9 以下ajax无法跨域的问题。只要add:jQuery.support.cors=true;即可

    if (!jQuery.support.cors && window.XDomainRequest) { var httpRegEx = /^https?:\/\//i; var ge ...