欢迎光临
我们一直在努力

.Net 缓存代理类 的初步考虑.-.NET教程,.NET Framework

建站超值云服务器,限时71元/月

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;//

stringbuilder sb = new stringbuilder(entity.entitytypename);

//用:分隔实体类列名

for(int i=0;i<keycolumns.length;i++)

{

sb.append(":");

sb.append(entity[keycolumns[i].columnname].tostring());

}

return sb.tostring();

}

注意:entitydata从dataset 继承过来.

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » .Net 缓存代理类 的初步考虑.-.NET教程,.NET Framework
分享到: 更多 (0)

相关推荐

  • 暂无文章