使用微软企业库缓存

using System.Data;
//
using Microsoft.Practices.EnterpriseLibrary.Caching;
using Microsoft.Practices.EnterpriseLibrary.Caching.Expirations;

/// <summary>
///使用微软企业库-缓存
/// </summary>
public class EnterpriseCache
{
    //实例化微软企业库缓存管理类
    CacheManager cm = CacheFactory.GetCacheManager();

    //1、放入缓存
    public void CachAllDept()
    {
        IDataReader dr = (new EnterpriseDA()).GetAllDeptReturnDRbySql();
        cm.Add("AllDept", dr);
        //cm.Remove();
    }

    //2、从缓存中获取
    public string[] GetAllDeptReturnDR()
    {
        string[] arr = { "" };
        IDataReader dr = (IDataReader)cm.GetData("AllDept");

        if (dr != null)
        {
            int i = 0;
            while (dr.Read())
            {
                arr[i] = dr.GetValue(2).ToString();
                i++;
            }
        }

        return arr;
    }
}

原文地址:https://www.cnblogs.com/sobaby/p/1269760.html