From: Gonzalo Paniagua Javier Date: Wed, 1 Oct 2003 02:16:44 +0000 (-0000) Subject: 2003-10-01 Gonzalo Paniagua Javier X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=commitdiff_plain;h=b2c4a00cd9cd23389c50e6be60c2da21758c58b7;p=mono.git 2003-10-01 Gonzalo Paniagua Javier * ConfigurationSettings.cs: patch by Eric Lindvall (eric@5stops.com) that improves performance by not reading the file more than once. svn path=/trunk/mcs/; revision=18462 --- diff --git a/mcs/class/System/System.Configuration/ChangeLog b/mcs/class/System/System.Configuration/ChangeLog index b81a74d70f2..12bf769c9c6 100644 --- a/mcs/class/System/System.Configuration/ChangeLog +++ b/mcs/class/System/System.Configuration/ChangeLog @@ -1,12 +1,18 @@ +2003-10-01 Gonzalo Paniagua Javier + + * ConfigurationSettings.cs: patch by Eric Lindvall (eric@5stops.com) + that improves performance by not reading the file more than once. + 2003-07-15 Andreas Nahr - * ConfigurationSettings.cs: Removed unused exception variable, fixes compiler warning + * ConfigurationSettings.cs: Removed unused exception variable, fixes + compiler warning 2003-06-16 Lluis Sanchez Gual - * ConfigurationSettings.cs: Avoid chicken-egg problem when reading machine.config. - Cannot use an uri to read mechine.config because web request module handelrs are - defined in machine.config. + * ConfigurationSettings.cs: Avoid chicken-egg problem when reading + machine.config. Cannot use an uri to read mechine.config because web + request module handelrs are defined in machine.config. 2003-03-02 Gonzalo Paniagua Javier diff --git a/mcs/class/System/System.Configuration/ConfigurationSettings.cs b/mcs/class/System/System.Configuration/ConfigurationSettings.cs index 254196bb53f..268763d1512 100644 --- a/mcs/class/System/System.Configuration/ConfigurationSettings.cs +++ b/mcs/class/System/System.Configuration/ConfigurationSettings.cs @@ -4,6 +4,7 @@ // Author: // Christopher Podurgiel (cpodurgiel@msn.com) // Gonzalo Paniagua Javier (gonzalo@ximian.com) +// Eric Lindvall (eric@5stops.com) // // C) Christopher Podurgiel // (c) 2002 Ximian, Inc. (http://www.ximian.com) @@ -129,6 +130,65 @@ namespace System.Configuration } } + // + // TODO: this should be changed to use the FileSystemWatcher + // + // -eric@5stops.com 9.20.2003 + // + class FileWatcherCache + { + Hashtable _cacheTable; + FileInfo _lastInfo; + string _filename; + + public FileWatcherCache (string filename) + { + _cacheTable = Hashtable.Synchronized (new Hashtable()); + _lastInfo = new FileInfo (filename); + _filename = filename; + } + + private bool HasFileChanged() + { + FileInfo currentInfo = new FileInfo (_filename); + + if (_lastInfo.LastWriteTime != currentInfo.LastWriteTime) + return (true); + + if (_lastInfo.CreationTime != currentInfo.CreationTime) + return (true); + + if (_lastInfo.Length != currentInfo.Length) + return (true); + + return (false); + } + + private void CheckFileChange() + { + if (HasFileChanged() == true) + { + _lastInfo = new FileInfo (_filename); + + _cacheTable.Clear(); + } + } + + public void Set (string key, object value) + { + CheckFileChange(); + + _cacheTable[key] = value; + } + + public object Get (string key) + { + CheckFileChange(); + + return (_cacheTable[key]); + } + } + class ConfigurationData { ConfigurationData parent; @@ -136,6 +196,8 @@ namespace System.Configuration string fileName; object removedMark = new object (); object groupMark = new object (); + object emptyMark = new object (); + FileWatcherCache fileCache = null; public ConfigurationData () : this (null) { @@ -170,6 +232,8 @@ namespace System.Configuration reader.Close(); } + fileCache = new FileWatcherCache (fileName); + return true; } @@ -242,7 +306,7 @@ namespace System.Configuration return doc; } - public object GetConfig (string sectionName) + object GetConfigInternal (string sectionName) { object handler = GetHandler (sectionName); if (handler == null) @@ -266,6 +330,30 @@ namespace System.Configuration return ((IConfigurationSectionHandler) handler).Create (parentConfig, null, doc.DocumentElement); } + public object GetConfig (string sectionName) + { + object config; + + // check to see if the handler is in the cache + config = fileCache.Get (sectionName); + + if (config == emptyMark) + return (null); + else if (config != null) + return (config); + else + { + config = GetConfigInternal (sectionName); + + if (config == null) + fileCache.Set (sectionName, emptyMark); + else + fileCache.Set (sectionName, config); + + return (config); + } + } + private object LookForFactory (string key) { object o = factories [key];