zoukankan      html  css  js  c++  java
  • 。net 文件依赖缓存

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    public partial class Default2 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string CacheKey = "cachetest";
            object objModel = GetCache(CacheKey);//从缓存中获取
            if (objModel == null)//缓存里没有
            {
                objModel = DateTime.Now;//把当前时间进行缓存
                if (objModel != null)
                {
                      System.Web.Caching.CacheDependency dep=new   System.Web.Caching.CacheDependency("C:\test.txt");
                    SetCache(CacheKey, objModel, dep);//写入缓存
                }
            }
            Label1.Text = objModel.ToString();
        }
        public static object GetCache(string CacheKey)
        {
            System.Web.Caching.Cache objCache = HttpRuntime.Cache;
            return objCache[CacheKey];
        }
    
        public static void SetCache(string CacheKey, object objObject,System.Web.Caching.CacheDependency dep)
        {
            System.Web.Caching.Cache objCache = HttpRuntime.Cache;
            objCache.Insert(CacheKey, objObject,dep,System.Web.Caching.Cache.NoAbsoluteExpiration,
                System.Web.Caching.Cache.NoSlidingExpiration, System.Web.Caching.CacheItemPriority.Default,null
    
                );
        }
    }
    

      

  • 相关阅读:
    Codeforces 601B. Lipshitz Sequence(单调栈)
    C++11正则表达式初探
    Codeforces 1051 D.Bicolorings(DP)
    数据库规范——学习小记
    2016 NEERC, Moscow Subregional Contest K. Knights of the Old Republic(Kruskal思想)
    10.2路径
    10.1jihe
    8/9三角形
    8/9,集合的运算
    6.2收费
  • 原文地址:https://www.cnblogs.com/mengluo/p/6074181.html
Copyright © 2011-2022 走看看