zoukankan      html  css  js  c++  java
  • 性能优化之缓存--文件缓存

    性能优化之缓存--文件缓存

    一、文件缓存介绍:

      1. 文件缓存就是把文件存储在缓存中,这次主要介绍的是通过chche进行缓存文件。

      2. 直接看看代码吧:具体如下:

           string filePath = Request.MapPath("File.txt");
                if (Cache["fileContent"] == null)
                {
                    //文件缓存依赖.
                    CacheDependency cDep = new CacheDependency(filePath);
                    string fileContent = File.ReadAllText(filePath);
                    Cache.Insert("fileContent", fileContent, cDep);
                    Response.Write("数据来自文件");
                }
                else
                {
                    Response.Write("数据来自缓存:"+Cache["fileContent"].ToString());
                }

      3. 嗯,其实还是很简单的,拿过去用就行,注意,cache是应用于web中,所以需要导入如下:

    using System.Web.Caching;

      4. 欢迎关注交流学习。

  • 相关阅读:
    HTML5中drag和drop使用
    E
    D
    杜教BM(解决线性递推式的模板)
    Myeclipse下载安装破解详细版
    D
    IDEA-连接MySQL连不上
    E
    C
    D. Ball(树状数组三维排序,求是否存在三个值都比自己大的人)
  • 原文地址:https://www.cnblogs.com/wangjinya/p/13759610.html
Copyright © 2011-2022 走看看