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

      

  • 相关阅读:
    C语言I博客作业10
    C言I博客作业09
    C言I博客作业08
    C语言I博客作业07
    C语言I博客作业06
    C语言博客园作业05
    使用注解方式生成Hibernate映射文件
    技术英语单词中英文对照
    spring监听器
    Servlet
  • 原文地址:https://www.cnblogs.com/mengluo/p/6074181.html
Copyright © 2011-2022 走看看