用System.Web.Caching.Cache保存数据类的缓存,用System.,System.W,ystem.We,stem.Web,tem.Web.,em.Web.C,m.Web.Ca,.Web.Cac,Web.Cach,eb.Cachi,b.Cachin,.Caching,Caching.,aching.C,ching.Ca,hing.Cac,ing.Cach,ng.Cache,g.Cache保,.Cache保存,Cache保存数,ache保存数据,che保存数据类,he保存数据类的,e保存数据类的缓 用System.Web.Caching.Cache保存数据类的缓存----编程资料集中营--八角123--bajiao123.com
编程资料集中营
 | 网站首页 | 文章中心 | 编程资料2 | 软件下载 | BT下载 | 八卦星闻 | 音乐在线 | 在线游戏 | 免费电影 | 进入问吧 | 
用System.Web.Caching.Cache保存数据类的缓存,///TheDataProviderclasscontainsasinglemethod,Instance(),whichreturnsaninstanceofthe///user-specifieddataproviderclass.///publicclassDataProvider{publicstaticIDataProviderInstance(),
您现在的位置: 编程资料,学习资料,c,c++,vc,vc++,java,jsp,j2ee,j2me,asp,php >> 文章中心 >> .NET 专区 >> NET 技术 >> 文章正文
【字体:
用System.Web.Caching.Cache保存数据类的缓存   进入问吧

本站地址:http://www.bajiao123.com

作者:admin    文章来源:本站    点击数:    更新时间:2007-6-10    

用System.Web.Caching.Cache保存数据类的缓存

/// The DataProvider class contains a single method, Instance(), which returns an instance of the
 /// user-specified data provider class.
 ///
 public class DataProvider
 {
  public static IDataProvider Instance()
  {
   //use the cache because the reflection used later is expensive
   Cache cache = System.Web.HttpContext.Current.Cache;

   if ( cache["IDataProvider"] == null )
   {
    //get the assembly path and class name from web.config
    String prefix = "";
    NameValueCollection context =

(NameValueCollection)ConfigurationSettings.GetConfig("appSettings");
    if (context == null)
    {
     //can not get settings
     return null;
    }

    String assemblyPath = context[prefix +

"DataProviderAssemblyPath"];
    String className = context[prefix +

"DataProviderClassName"];

    // assemblyPath presented in virtual form, must convert to

physical path
    assemblyPath =

HttpContext.Current.Server.MapPath(HttpContext.Current.Request.ApplicationPath + "/bin/" +

assemblyPath);     

    // Uuse reflection to store the constructor of the class

that implements IWebForumDataProvider
    try
    {
     cache.Insert( "IDataProvider", Assembly.LoadFrom(

assemblyPath).GetType( className ).GetConstructor(new Type[0]), new CacheDependency(

assemblyPath ) );
    }
    catch (Exception)
    {

     // could not locate DLL file
     HttpContext.Current.Response.Write("<b>ERROR:</b>

Could not locate file: <code>" + assemblyPath + "</code> or could not locate class <code>" +

className + "</code> in file.");
     HttpContext.Current.Response.End();
    }
   }
   return (IDataProvider)( 

((ConstructorInfo)cache["IDataProvider"]).Invoke(null) );
  }
 }


   

进入问吧

本站地址:http://www.bajiao123.com

文章录入:admin    责任编辑:admin 
高级搜索
编程资料集中营