首页 > Web开发 > 详细

。net 文件依赖缓存

时间:2016-11-17 17:52:37      阅读:246      评论:0      收藏:0      [点我收藏+]
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 文件依赖缓存

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!