用System.Web.Caching.Cache保存数据类的缓存
|
{ 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 ) (NameValueCollection)ConfigurationSettings.GetConfig("appSettings"); String assemblyPath = context[prefix + "DataProviderAssemblyPath"]; "DataProviderClassName"]; // assemblyPath presented in virtual form, must convert to physical path HttpContext.Current.Server.MapPath(HttpContext.Current.Request.ApplicationPath + "/bin/" + assemblyPath); // Uuse reflection to store the constructor of the class that implements IWebForumDataProvider assemblyPath).GetType( className ).GetConstructor(new Type[0]), new CacheDependency( assemblyPath ) ); // could not locate DLL file Could not locate file: <code>" + assemblyPath + "</code> or could not locate class <code>" + className + "</code> in file."); ((ConstructorInfo)cache["IDataProvider"]).Invoke(null) ); 源代码网推荐 源代码网供稿. |
