用System.Web.Caching.Cache保存数据类的缓存
2008-07-02 01:11
260 查看
/// 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) );
}
}
作者Blog:http://blog.csdn.net/hunter_gio/
相关文章
/// 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) );
}
}
作者Blog:http://blog.csdn.net/hunter_gio/
相关文章
A simple win32 windows application |
C++中几个比较不常用的关键字 |
网上看到的排序源码, 准备面试的朋友可以看看 |
用System.Web.Caching.Cache保存数据类的缓存 |
一本书, 一段源码, 推荐给大家 |
相关文章推荐
- 用System.Web.Caching.Cache保存数据类的缓存
- .Net内部缓存System.Web.Caching.Cache 和Redis缓存缓存工厂切换
- System.Web.Caching.Cache Web 缓存的使用
- asp.net 数据缓存System.Web.Caching.Cache 实例运用
- System.Web.Caching.Cache
- 深入System.Web.Caching命名空间 教你Hold住缓存管理(二)
- System.Web.Caching 缓存管理2
- System.Web.UI.Page.Cache 页面 缓存 清除
- System.Web.Caching 缓存管理3
- 清除System.Web.HttpRuntime.Cache缓存
- System.Web.Caching.Cache
- 深入System.Web.Caching命名空间 教你Hold住缓存管理(三)
- 第一节:从程序集的角度分析System.Web.Caching.Cache ,并完成基本封装。
- (转)深入System.Web.Caching命名空间 教你Hold住缓存管理(一)
- System.Web.Caching.Cache删除某键后,希望同时触发其它动作(关键时刻,还是事件靠的住)
- 深入System.Web.Caching命名空间 教你Hold住缓存管理
- 深入System.Web.Caching命名空间 教你Hold住缓存管理(一)
- memcache实战之四:接口编程(分别用asp.net自带的System.Web.Caching,以及分布式缓存MemcachedProviders)来实现缓存接口
- .net System.Web.Caching.Cache 缓存类使用详解
- System.Web.Caching.Cache的简单介绍