zoukankan      html  css  js  c++  java
  • cacheHelper

    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Web;
    using System.Web.Caching;

    namespace AddSdJobs
    {
    public static class CacheHelper
    {
    static Cache _cache = HttpRuntime.Cache;

    /// <summary>
    /// 获取缓存
    /// </summary>
    /// <param name="key"></param>
    /// <returns></returns>
    public static object Get(string key)
    {
    return _cache.Get(key);
    }

    /// <summary>
    /// 设置缓存
    /// </summary>
    /// <param name="key"></param>
    /// <param name="value"></param>
    public static void Set(string key, object value)
    {
    _cache.Insert(key, value);
    }

    /// <summary>
    /// 设置指定时间内有效的缓存
    /// </summary>
    /// <param name="key"></param>
    /// <param name="value"></param>
    /// <param name="expireSeconds">缓存有效时间,单位秒</param>
    public static void Set(string key, object value, long expireSeconds)
    {
    _cache.Insert(key, value, null, DateTime.UtcNow.AddSeconds(expireSeconds), TimeSpan.Zero);
    }

    /// <summary>
    /// 清除指定key的缓存内容
    /// </summary>
    /// <param name="key"></param>
    public static void Remove(string key)
    {
    _cache.Remove(key);
    }

    /// <summary>
    /// 清除关键字为某一指定前缀的所有缓存内容
    /// </summary>
    /// <param name="keyPrefix">缓存关键字前缀</param>
    public static void RemoveCacheByKeyPrefix(string keyPrefix)
    {
    System.Web.Caching.Cache _cache = HttpRuntime.Cache;
    IDictionaryEnumerator CacheEnum = _cache.GetEnumerator();
    ArrayList al = new ArrayList();
    while (CacheEnum.MoveNext())
    {
    if (CacheEnum.Key.ToString().StartsWith(keyPrefix))
    {
    al.Add(CacheEnum.Key);
    }
    }

    foreach (string key in al)
    {
    _cache.Remove(key);
    }
    }

    /// <summary>
    /// 清除所有缓存内容
    /// </summary>
    public static void RemoveAllCache()
    {
    System.Web.Caching.Cache _cache = HttpRuntime.Cache;
    IDictionaryEnumerator CacheEnum = _cache.GetEnumerator();
    ArrayList al = new ArrayList();
    while (CacheEnum.MoveNext())
    {
    al.Add(CacheEnum.Key);
    }

    foreach (string key in al)
    {
    _cache.Remove(key);
    }
    }
    }
    }

  • 相关阅读:
    边框颜色为 tintColor 的 UIButton
    iPhone: 在 iPhone app 里使用 UIPopoverController
    CCSprite: fade 效果切换图片
    iOS7以上: 实现如“日历”的 NavigationBar
    jqgrid自适应宽度
    NFine框架学习
    sql server 查看数据库文件的大小
    eclipse没有server选项
    MySql的数据导入到Sql Server数据库中
    eclispe javaw.exe in your current path的解决方法
  • 原文地址:https://www.cnblogs.com/zhshlimi/p/5415497.html
Copyright © 2011-2022 走看看