private void BeginWach() { if (watcher != null) { watcher.Dispose(); } watcher = new CacheDependency(FaceDirectory); IsWathing = true; }
void IDisposable.Dispose() { if (_fileDependency != null) { _fileDependency.Dispose(); } }
public override void Dispose() { if (dependency != null) { dependency.Dispose(); dependency = null; } }
/// <internalonly/> public override void Dispose() { if (_cacheDependency != null) { _cacheDependency.Dispose(); _cacheDependency = null; } base.Dispose(); }
protected virtual void Dispose(bool disposing) { if (disposing) { if (_dependencies != null) { _dependencies.Dispose(); _dependencies = null; } } }
//Method that does the actual disposal of resources protected virtual void Dispose(bool disposing) { if ((disposing)) { if (_cacheDependency != null) { _cacheDependency.Dispose(disposing); } if (_systemCacheDependency != null) { _systemCacheDependency.Dispose(); } _fileNames = null; _cacheKeys = null; _cacheDependency = null; _systemCacheDependency = null; } }
public void Dispose() { Internal.Dispose(); }
protected internal override void Render(HtmlTextWriter output) { CacheDependency dependency = null; if (this._outputString != null) { output.Write(this._outputString); this.RegisterValidationEvents(); } else if (this._cachingDisabled || !RuntimeConfig.GetAppConfig().OutputCache.EnableFragmentCache) { this._cachedCtrl.RenderControl(output); } else { string str; DateTime noAbsoluteExpiration; TimeSpan noSlidingExpiration; if (this._sqlDependency != null) { dependency = SqlCacheDependency.CreateOutputCacheDependency(this._sqlDependency); } this._cacheEntry.CssStyleString = this.GetCssStyleRenderString(output.GetType()); StringWriter tw = new StringWriter(); HtmlTextWriter writer = Page.CreateHtmlTextWriterFromType(tw, output.GetType()); TextWriter writer3 = this.Context.Response.SwitchWriter(tw); try { this.Page.PushCachingControl(this); this._cachedCtrl.RenderControl(writer); this.Page.PopCachingControl(); } finally { this.Context.Response.SwitchWriter(writer3); } this._cacheEntry.OutputString = tw.ToString(); output.Write(this._cacheEntry.OutputString); CacheDependency dependencies = this._cacheDependency; if (dependency != null) { if (dependencies == null) { dependencies = dependency; } else { AggregateCacheDependency dependency3 = new AggregateCacheDependency(); dependency3.Add(new CacheDependency[] { dependencies }); dependency3.Add(new CacheDependency[] { dependency }); dependencies = dependency3; } } ControlCachedVary cachedVary = null; if (((this._varyByParamsCollection == null) && (this._varyByControlsCollection == null)) && (this._varyByCustom == null)) { str = this._cacheKey; } else { string[] varyByParams = null; if (this._varyByParamsCollection != null) { varyByParams = this._varyByParamsCollection.GetParams(); } cachedVary = new ControlCachedVary(varyByParams, this._varyByControlsCollection, this._varyByCustom); HashCodeCombiner combinedHashCode = new HashCodeCombiner(this._nonVaryHashCode); str = this.ComputeVaryCacheKey(combinedHashCode, cachedVary); } if (this._useSlidingExpiration) { noAbsoluteExpiration = Cache.NoAbsoluteExpiration; noSlidingExpiration = (TimeSpan)(this._utcExpirationTime - DateTime.UtcNow); } else { noAbsoluteExpiration = this._utcExpirationTime; noSlidingExpiration = Cache.NoSlidingExpiration; } try { OutputCache.InsertFragment(this._cacheKey, cachedVary, str, this._cacheEntry, dependencies, noAbsoluteExpiration, noSlidingExpiration, this._provider); } catch { if (dependencies != null) { dependencies.Dispose(); } throw; } } }
public static bool AddToCacheDependency(string key, object value) { bool retVal = false; if (!ConfigSettings.CentralManagement & ConfigSettings.EnableCache) { FileStream fileStream = null; string fileName = null; fileName = s_CacheDirectory + key + ".txt"; // ensure the file exists if not then create one if (!File.Exists(fileName)) { try { File.Create(fileName).Close(); } catch (IOException) { MDirectoryProfile DirectoryProfile = new MDirectoryProfile(); FileUtility.CreateDirectory(HttpContext.Current.Server.MapPath("~\\"), "CacheDependency", DirectoryProfile); File.Create(fileName).Close(); } HttpContext.Current.Application.Lock(); HttpContext.Current.Application[key + "WriteCache"] = true; HttpContext.Current.Application.UnLock(); } // re-write the dependancy file based on the application variable // file replication will cause the other servers to remove their cache item if (HttpContext.Current.Application[key + "WriteCache"] == null) { HttpContext.Current.Application[key + "WriteCache"] = "true"; } if (Convert.ToBoolean(HttpContext.Current.Application[key + "WriteCache"].ToString(), CultureInfo.InvariantCulture)) { try { fileStream = new FileStream(fileName, FileMode.Truncate); using (StreamWriter writer = new StreamWriter(fileStream)) { writer.WriteLine(DateTime.Now.TimeOfDay); } HttpContext.Current.Application.Lock(); HttpContext.Current.Application[key + "WriteCache"] = false; HttpContext.Current.Application.UnLock(); } catch (Exception) { throw; } finally { if (fileStream != null) { fileStream.Dispose(); } } } // cache it for future use CacheItemRemovedCallback onCacheRemove = null; CacheDependency mCacheDependency = null; try { onCacheRemove = new CacheItemRemovedCallback(CheckCallback); mCacheDependency = new CacheDependency(fileName); if ((value != null)) { HttpContext.Current.Cache.Add(key, value, mCacheDependency, System.Web.Caching.Cache.NoAbsoluteExpiration, System.Web.Caching.Cache.NoSlidingExpiration, CacheItemPriority.Default, onCacheRemove); } } catch (Exception) { throw; } finally { if (mCacheDependency != null) { mCacheDependency.Dispose(); } } // used in the orginal vb code and no eq. for the Err object exists in c# // assume that if no exception has happened the set retVal=true //if (Err().Number == 0) retVal = true; retVal = true; } else { retVal = true; } return(retVal); }