2 // MemoryCacheEntryChangeMonitor.cs
5 // Marek Habersack <mhabersack@novell.com>
7 // Copyright (C) 2010 Novell, Inc. (http://novell.com/)
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 using System.Collections;
30 using System.Collections.Generic;
31 using System.Collections.ObjectModel;
34 namespace System.Runtime.Caching
36 sealed class MemoryCacheEntryChangeMonitor : CacheEntryChangeMonitor
38 ReadOnlyCollection <string> cacheKeys;
39 DateTimeOffset lastModified;
43 public override ReadOnlyCollection <string> CacheKeys {
44 get { return cacheKeys; }
47 public override DateTimeOffset LastModified {
48 get { return lastModified; }
51 public override string RegionName {
55 public override string UniqueId {
56 get { return uniqueId; }
59 public MemoryCacheEntryChangeMonitor (MemoryCache owner, IEnumerable <string> keys)
62 this.lastModified = DateTimeOffset.MinValue;
65 var sb = new StringBuilder ();
66 var list = new List <string> ();
67 foreach (string key in keys) {
68 mce = owner.GetEntry (key);
71 // LAMESPEC: this is what's happening
72 DateTimeOffset modtime;
73 modtime = new DateTimeOffset (mce != null ? mce.LastModified : DateTime.MinValue);
74 if (this.lastModified < modtime)
75 this.lastModified = modtime;
77 // LAMESPEC: this is what is supposed to be happening
80 sb.Append ("{0}{1:x}", key, DateTime.MinValue.Ticks);
84 DateTime modtime = mce.LastModified;
85 if (this.lastModtime < modtime)
86 this.lastModtime = new DateTimeOffset (modtime);
88 sb.AppendFormat ("{0}{1:X}", key, modtime.Ticks);
90 this.uniqueId = sb.ToString ();
91 this.cacheKeys = new ReadOnlyCollection <string> (list);
93 // TODO: hook up to change events on MemoryCache
96 protected override void Dispose (bool disposing)