Ejemplo n.º 1
0
        public void Add( int hashedKey, object scalarResult )
        {
            if ( ConfigurationHelper.Instance.TestMode )
                return;

            if ( !_cache.ContainsKey( hashedKey ) )
                _cache.Add( hashedKey, new ResultCacheEntry( hashedKey, scalarResult ) );
            else
                _cache[ hashedKey ] = new ResultCacheEntry( hashedKey, scalarResult );

            Save( );
        }
Ejemplo n.º 2
0
        private void Save( )
        {
            ResultCacheEntry[ ] cacheEntrys = new ResultCacheEntry[ _cache.Count ];

            int i = 0;
            foreach ( KeyValuePair<int, ResultCacheEntry> kvp in _cache )
            {
                cacheEntrys[ i ] = kvp.Value;
                i++;
            }

            lock ( syncRoot )
            {
                TextWriter writer = new StreamWriter( ConfigurationHelper.Instance.CacheFile, false );
                XmlSerializer serializer = new XmlSerializer( typeof( ResultCacheEntry[ ] ) );
                serializer.Serialize( writer, cacheEntrys );
                writer.Close( );
            }
        }