• 网页 缓存


    掉用缓存方法:

     var listModel =ProclamationCache.GetProclamationList();

    //实现方法

    public static List<ProclamationModel> GetProclamationList()
    {
    var cache = GetTopProclamationList();
    if (cache != null)
    {
    return cache;
    }
    return null;
    }

    //实现调用方法

    private static List<ProclamationModel> GetTopProclamationList()
    {
    string CacheKey_ProList = "_CacheKey_ProList";
    int CacheOutTime = ConfigHelperBLL.CacheOutTime;

    List<ProclamationModel> listModel = HttpRuntime.Cache[CacheKey_ProList] as List<ProclamationModel>;
    if (listModel == null)
    {
    listModel = GetProclamationList_ForCache(0, 30);
    HttpRuntime.Cache.Insert(CacheKey_ProList, listModel, null,
    DateTime.Now.AddSeconds(CacheOutTime), System.Web.Caching.Cache.NoSlidingExpiration, GetTopProclamationList_UpdateCallback);
    }
    return listModel;
    }

    //实现调用方法

    private static void GetTopProclamationList_UpdateCallback(string key, CacheItemUpdateReason reason, out object expensiveObject, out CacheDependency dependency, out DateTime absoluteExpiration, out TimeSpan slidingExpiration)
    {
    int CacheOutTime = ConfigHelperBLL.CacheOutTime;
    expensiveObject = GetProclamationList_ForCache(0, 30);
    dependency = null;
    absoluteExpiration = DateTime.Now.AddSeconds(CacheOutTime);
    slidingExpiration = Cache.NoSlidingExpiration;
    }

    //实现调用方法

    public static int CacheOutTime
    {
    get
    {
    int time = 0;
    if(!int.TryParse(System.Configuration.ConfigurationManager.AppSettings["CacheOutTime"],out time))
    {
    time = 3;
    }
    return time;
    }
    }

  • 相关阅读:
    原型污染
    C#之抛异常
    为什么['1', '7', '11'].map(parseInt) returns [1, NaN, 3]?
    Linux
    Linux
    Linux
    Linux
    Linux
    Linux
    其他
  • 原文地址:https://www.cnblogs.com/dandanwozhishidan/p/5238774.html
Copyright © 2020-2023  润新知