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));

    }

  • 相关阅读:
    【HDOJ】2267 How Many People Can Survive
    【HDOJ】2268 How To Use The Car
    【HDOJ】2266 How Many Equations Can You Find
    【POJ】2278 DNA Sequence
    【ZOJ】3430 Detect the Virus
    【HDOJ】2896 病毒侵袭
    求奇数的乘积
    平方和与立方和
    求数列的和
    水仙花数
  • 原文地址:https://www.cnblogs.com/AngelLee2009/p/2189591.html
Copyright © 2011-2022 走看看