protected virtual PluginDomainInstanceLoader GetPluginInstanceLoader(string pluginConfigFilePath, string pluginFilePath) { if (string.IsNullOrEmpty(pluginConfigFilePath) || (PluginInstanceLoadersCacheTimeInMinutes <= 0)) { // This is not an expensive case with string.IsNullOrEmpty(pluginConfigFilePath), since we are // not creating spring objects, so don't cache // // OR // // we've specified to turn off the cache with PluginInstanceLoadersCacheTimeInMinutes <= 0 return(new PluginDomainInstanceLoader(pluginConfigFilePath, pluginFilePath)); } const string CACHED_PLUGIN_INSTANCE_LOADERS = "_CACHED_PLUGIN_INSTANCE_LOADERS"; string cacheName = CACHED_PLUGIN_INSTANCE_LOADERS + "_" + pluginConfigFilePath + "_" + pluginFilePath; PluginDomainInstanceLoader loader; lock (s_CachedPluginInstanceLoadersLock) { loader = HttpRuntime.Cache[cacheName] as PluginDomainInstanceLoader; } if (loader != null) { return(loader); } string parentDirPath = Path.GetDirectoryName(Path.GetDirectoryName(pluginFilePath)); loader = new PluginDomainInstanceLoader(pluginConfigFilePath, pluginFilePath); PluginDomainInstanceLoader loaderAlreadyThere = null; lock (s_CachedPluginInstanceLoadersLock) { loaderAlreadyThere = HttpRuntime.Cache[cacheName] as PluginDomainInstanceLoader; if (loaderAlreadyThere == null) { loader.Acquire(); HttpRuntime.Cache.Add(cacheName, loader, new CacheDependency(parentDirPath), Cache.NoAbsoluteExpiration, TimeSpan.FromMinutes(PluginInstanceLoadersCacheTimeInMinutes), CacheItemPriority.AboveNormal, OnCachePluginDomainInstanceLoaderRemovedCallback); } } if (loaderAlreadyThere != null) { // Switch over to already cached instance DisposableBase.SafeDispose(ref loader); loader = loaderAlreadyThere; } return(loader); }
public PluginDisposer(PluginDomainInstanceLoader loader) { _loader = loader; _loader.Acquire(); }