码迷,mamicode.com
首页 > Web开发 > 详细

。net 文件依赖缓存

时间:2016-11-17 17:55:36      阅读:175      评论:0      收藏:0      [点我收藏+]

标签:tostring   pen   ret   pre   class   获取   时间   highlight   protect   

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

            );
    }
}

  

。net 文件依赖缓存

标签:tostring   pen   ret   pre   class   获取   时间   highlight   protect   

原文地址:http://www.cnblogs.com/mengluo/p/6074181.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!