.Net 缓存代理类 的初步考虑.
EntityData为实体数据类我们这里将实体数据进行缓存,缓存方法是
//从Web.Config取得对缓存过期的设置
ICacheItemExpiration[] ice=ExpireTerm.GetExpirationPolicy();
//获得缓冲对象
CacheManager cm=CacheManager.GetCacheManager();
存储
cm.Add(EntityKeyCreator.CreateKey(entity),entity,ice,CacheItemPriority.Normal,null);
此类可以做实体代理类
using Microsoft.ApplicationBlocks.Cache;
/// <summary>
/// 缓冲实体
/// </summary>
/// <param name="entity">实体数据</param>
public static void CacheEntity(EntityData entity)
{
if(entity.IsEmpty)
return;
ICacheItemExpiration[] ice=ExpireTerm.GetExpirationPolicy();
//获得缓冲对象
CacheManager cm=CacheManager.GetCacheManager();
//存储
cm.Add(ExpireTerm.CreateKey(entity),entity,ice,CacheItemPriority.Normal,null);
}
ExpireTerm.class
using Microsoft.ApplicationBlocks.Cache;
internal static ICacheItemExpiration[] GetExpirationPolicy()
{
if(Object.Equals(configSetting,null))
{
configSetting = (ICacheItemExpiration[])ConfigurationSettings.GetConfig("TopCoolExpireTerm");
}
return configSetting;
}
internal static string CreateKey(EntityData entity)
{
DataSet ds = new DataSet();
DataColumn[] keyColumns;
if(entity.Tables.Contains(entity.MainTableName))
keyColumns = entity.Tables[entity.MainTableName].PrimaryKey;
else
keyColumns = entity.CurrentTable.PrimaryKey;//
补充:asp.net教程,基础入门