}                                           // hide default .ctor

        private void InitDisposableMembers(MemoryCache cache)
        {
            bool dispose = true;

            try
            {
                bool   hasChanged = false;
                string uniqueId   = null;
                _dependencies = new List <MemoryCacheEntry>(_keys.Count);
                if (_keys.Count == 1)
                {
                    string           k          = _keys[0];
                    MemoryCacheEntry entry      = cache.GetEntry(k);
                    DateTime         utcCreated = s_DATETIME_MINVALUE_UTC;
                    StartMonitoring(cache, entry, ref hasChanged, ref utcCreated);
                    uniqueId      = k + utcCreated.Ticks.ToString("X", CultureInfo.InvariantCulture);
                    _lastModified = utcCreated;
                }
                else
                {
                    int capacity = 0;
                    foreach (string key in _keys)
                    {
                        capacity += key.Length + MAX_CHAR_COUNT_OF_LONG_CONVERTED_TO_HEXADECIMAL_STRING;
                    }
                    StringBuilder sb = new StringBuilder(capacity);
                    foreach (string key in _keys)
                    {
                        MemoryCacheEntry entry      = cache.GetEntry(key);
                        DateTime         utcCreated = s_DATETIME_MINVALUE_UTC;
                        StartMonitoring(cache, entry, ref hasChanged, ref utcCreated);
                        sb.Append(key);
                        sb.Append(utcCreated.Ticks.ToString("X", CultureInfo.InvariantCulture));
                        if (utcCreated > _lastModified)
                        {
                            _lastModified = utcCreated;
                        }
                    }
                    uniqueId = sb.ToString();
                }
                _uniqueId = uniqueId;
                if (hasChanged)
                {
                    OnChanged(null);
                }
                dispose = false;
            }
            finally
            {
                InitializationComplete();
                if (dispose)
                {
                    Dispose();
                }
            }
        }
Example #2
0
        private void InitDisposableMembers(MemoryCache cache)
        {
            bool flag = true;

            try
            {
                bool   hasChanged = false;
                string str        = null;
                this._dependencies = new List <MemoryCacheEntry>(this._keys.Count);
                if (this._keys.Count == 1)
                {
                    string           key        = this._keys[0];
                    MemoryCacheEntry entry      = cache.GetEntry(key);
                    DateTime         utcCreated = DATETIME_MINVALUE_UTC;
                    this.StartMonitoring(cache, entry, ref hasChanged, ref utcCreated);
                    str = key + utcCreated.Ticks.ToString("X", CultureInfo.InvariantCulture);
                    this._lastModified = utcCreated;
                }
                else
                {
                    int capacity = 0;
                    foreach (string str3 in this._keys)
                    {
                        capacity += str3.Length + 0x10;
                    }
                    StringBuilder builder = new StringBuilder(capacity);
                    foreach (string str4 in this._keys)
                    {
                        MemoryCacheEntry entry2 = cache.GetEntry(str4);
                        DateTime         time2  = DATETIME_MINVALUE_UTC;
                        this.StartMonitoring(cache, entry2, ref hasChanged, ref time2);
                        builder.Append(str4);
                        builder.Append(time2.Ticks.ToString("X", CultureInfo.InvariantCulture));
                        if (time2 > this._lastModified)
                        {
                            this._lastModified = time2;
                        }
                    }
                    str = builder.ToString();
                }
                this._uniqueId = str;
                if (hasChanged)
                {
                    base.OnChanged(null);
                }
                flag = false;
            }
            finally
            {
                base.InitializationComplete();
                if (flag)
                {
                    base.Dispose();
                }
            }
        }
 private void InitDisposableMembers(MemoryCache cache)
 {
     bool flag = true;
     try
     {
         bool hasChanged = false;
         string str = null;
         this._dependencies = new List<MemoryCacheEntry>(this._keys.Count);
         if (this._keys.Count == 1)
         {
             string key = this._keys[0];
             MemoryCacheEntry entry = cache.GetEntry(key);
             DateTime utcCreated = DATETIME_MINVALUE_UTC;
             this.StartMonitoring(cache, entry, ref hasChanged, ref utcCreated);
             str = key + utcCreated.Ticks.ToString("X", CultureInfo.InvariantCulture);
             this._lastModified = utcCreated;
         }
         else
         {
             int capacity = 0;
             foreach (string str3 in this._keys)
             {
                 capacity += str3.Length + 0x10;
             }
             StringBuilder builder = new StringBuilder(capacity);
             foreach (string str4 in this._keys)
             {
                 MemoryCacheEntry entry2 = cache.GetEntry(str4);
                 DateTime time2 = DATETIME_MINVALUE_UTC;
                 this.StartMonitoring(cache, entry2, ref hasChanged, ref time2);
                 builder.Append(str4);
                 builder.Append(time2.Ticks.ToString("X", CultureInfo.InvariantCulture));
                 if (time2 > this._lastModified)
                 {
                     this._lastModified = time2;
                 }
             }
             str = builder.ToString();
         }
         this._uniqueId = str;
         if (hasChanged)
         {
             base.OnChanged(null);
         }
         flag = false;
     }
     finally
     {
         base.InitializationComplete();
         if (flag)
         {
             base.Dispose();
         }
     }
 }
        private MemoryCacheEntryChangeMonitor() {} // hide default .ctor

        private void InitDisposableMembers(MemoryCache cache) {
            bool dispose = true;
            try {
                bool hasChanged = false;
                string uniqueId = null;
                _dependencies = new List<MemoryCacheEntry>(_keys.Count);
                if (_keys.Count == 1) {
                    string k = _keys[0];
                    MemoryCacheEntry entry = cache.GetEntry(k);
                    DateTime utcCreated = DATETIME_MINVALUE_UTC;
                    StartMonitoring(cache, entry, ref hasChanged, ref utcCreated);
                    uniqueId = k + utcCreated.Ticks.ToString("X", CultureInfo.InvariantCulture);
                    _lastModified = utcCreated;
                }
                else {
                    int capacity = 0;
                    foreach (string key in _keys) {
                        capacity += key.Length + MAX_CHAR_COUNT_OF_LONG_CONVERTED_TO_HEXADECIMAL_STRING;
                    }
                    StringBuilder sb = new StringBuilder(capacity);
                    foreach (string key in _keys) {
                        MemoryCacheEntry entry = cache.GetEntry(key);
                        DateTime utcCreated = DATETIME_MINVALUE_UTC;
                        StartMonitoring(cache, entry, ref hasChanged, ref utcCreated);
                        sb.Append(key);
                        sb.Append(utcCreated.Ticks.ToString("X", CultureInfo.InvariantCulture));
                        if (utcCreated > _lastModified) {
                            _lastModified = utcCreated;
                        }
                    }
                    uniqueId = sb.ToString();
                }
                _uniqueId = uniqueId;
                if (hasChanged) {
                    OnChanged(null);
                }
                dispose = false;
            }
            finally {
                InitializationComplete();
                if (dispose) {
                    Dispose();
                }                
            }
        }
Example #5
0
        public MemoryCacheEntryChangeMonitor(MemoryCache owner, IEnumerable <string> keys)
        {
            this.owner        = owner;
            this.lastModified = DateTimeOffset.MinValue;

            MemoryCacheEntry mce;
            var sb   = new StringBuilder();
            var list = new List <string> ();

            foreach (string key in keys)
            {
                mce = owner.GetEntry(key);
                list.Add(key);
#if true
                // LAMESPEC: this is what's happening
                DateTimeOffset modtime;
                modtime = new DateTimeOffset(mce != null ? mce.LastModified : DateTime.MinValue);
                if (this.lastModified < modtime)
                {
                    this.lastModified = modtime;
                }
#else
                // LAMESPEC: this is what is supposed to be happening
                if (mce == null)
                {
                    OnChanged(null);
                    sb.Append("{0}{1:x}", key, DateTime.MinValue.Ticks);
                    continue;
                }

                DateTime modtime = mce.LastModified;
                if (this.lastModtime < modtime)
                {
                    this.lastModtime = new DateTimeOffset(modtime);
                }
#endif
                sb.AppendFormat("{0}{1:X}", key, modtime.Ticks);
            }
            this.uniqueId  = sb.ToString();
            this.cacheKeys = new ReadOnlyCollection <string> (list);

            // TODO: hook up to change events on MemoryCache
        }
		public MemoryCacheEntryChangeMonitor (MemoryCache owner, IEnumerable <string> keys)
		{
			this.owner = owner;
			this.lastModified = DateTimeOffset.MinValue;

			MemoryCacheEntry mce;
			var sb = new StringBuilder ();
			var list = new List <string> ();
			foreach (string key in keys) {
				mce = owner.GetEntry (key);
				list.Add (key);
#if true
				// LAMESPEC: this is what's happening
				DateTimeOffset modtime;
				modtime = new DateTimeOffset (mce != null ? mce.LastModified : DateTime.MinValue);
				if (this.lastModified < modtime)
					this.lastModified = modtime;
#else
				// LAMESPEC: this is what is supposed to be happening
				if (mce == null) {
					OnChanged (null);
					sb.Append ("{0}{1:x}", key, DateTime.MinValue.Ticks);
					continue;
				}
				
				DateTime modtime = mce.LastModified;
				if (this.lastModtime < modtime)
					this.lastModtime = new DateTimeOffset (modtime);
#endif
				sb.AppendFormat ("{0}{1:X}", key, modtime.Ticks);
			}
			this.uniqueId = sb.ToString ();
			this.cacheKeys = new ReadOnlyCollection <string> (list);

			// TODO: hook up to change events on MemoryCache
		}