zoukankan      html  css  js  c++  java
  • 必备知识:缓存

    缓存是程序提高性能最直接有效的手段

    页面缓存,文件缓存依赖,数据库缓存依赖

    一.页面缓存://.net自己帮我们实现,我们只负责进行配置

    配置1:<%@ OutputCache Duration="" VaryByParam="none" %>//Duration时间单位是秒,VaryByParam多个以;分隔开。

    配置2:<%@ OutputCache CacheProfile="myPageCache" VaryByParam="none" %>

    <caching>

        <outputCache enableOutputCache="true"/>

        <outputCacheSettings>

            <outputCacheProfiles>

                <add name="myPageCache" duration="" enabled="true"/>

            <outputCacheProfiles>

        </outputCacheSettings>

    </caching>

    二.文件缓存依赖://需要我们自己加入到缓存中

    //键

    String key = "TimeNow";

    //试图从缓存中获取时间

    string strTime = HttpRuntime.Cache[key];

    if(string.IsNullOrEmpty(strTime))

    {

        strTime = DateTime.Now.ToString();

        CacheDependency dep = new CacheDependency(Server.MapPath("dep.txt"));

        Cache.Insert(key,strTime,dep);

    }

    //使用strTime

    三.数据库缓存依赖

    生成表(AspNet_SqlCacheTablesChangeNotification)及存储过程:c:\Windows\Microsoft.NET\Framework\v2.0.50727\aspnet_regsql.exe

    实例:aspnet_regsql.exe –S localhost –E –d CacheTest –ed(为SQL缓存依赖启用该数据库)

    说明:-S服务器; –E Windows身份验证;-d 数据库名称;

    aspnet_regsql.exe –S localhost – E –d CacheTest –t Student –et(为SQL缓存依赖项启用该表)

    AggregateCacheDependency dependency = new AggregateCacheDependency();

    string dbName = ConfigurationManger.AppSettings["dbName"];

    String tbStr str = ConfigurationManger.AppSettings["tbName"];

    Foreach(string table in tables)

    {

        dependency.add(new SqlCacheDependency(dbName,table));

    }

  • 相关阅读:
    关于图片色彩位深度与颜色模式(待完善)
    Android 跨进程数据共享
    Android实现模拟表单上传
    Android数据库无缝升级方案
    Dagger2在Android开发中的应用
    Dagger2学习笔记
    Android开发随手记
    Android Shape Divider
    带你玩转java多线程系列 “道篇” 多线程的优势及利用util.concurrent包测试单核多核下多线程的效率
    带你玩转java多线程系列 二 Thread 和 Runnable
  • 原文地址:https://www.cnblogs.com/AngelLee2009/p/2189591.html
Copyright © 2011-2022 走看看