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

    }

  • 相关阅读:
    webpack基础
    LeetCode232. 用栈实现队列做题笔记
    mysql 时间加减一个月
    leetcode 1381. 设计一个支持增量操作的栈 思路与算法
    LeetCode 141. 环形链表 做题笔记
    leetcode 707. 设计链表 做题笔记
    leetcode 876. 链表的中间结点 做题笔记
    leetcode 143. 重排链表 做题笔记
    leetcode 1365. 有多少小于当前数字的数字 做题笔记
    LeetCode1360. 日期之间隔几天 做题笔记
  • 原文地址:https://www.cnblogs.com/AngelLee2009/p/2189591.html
Copyright © 2011-2022 走看看