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

    }

  • 相关阅读:
    [LeetCode] 1092. Shortest Common Supersequence
    [LeetCode] 1091. Shortest Path in Binary Matrix
    [LeetCode] 1090. Largest Values From Labels
    [LeetCode] 1089. Duplicate Zeros
    git log
    Java-Note
    (转载)深入解析String#intern
    Android——LruCache源码解析
    (转载)gcc编译选项总结
    Java——LinkedHashMap源码解析
  • 原文地址:https://www.cnblogs.com/AngelLee2009/p/2189591.html
Copyright © 2011-2022 走看看