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.Generic;
30 using System.Reflection;
31 using System.Runtime.Caching;
33 namespace MonoTests.Common
35 class PokerObjectCache : ObjectCache
37 Dictionary <string, object> cache;
39 Dictionary<string, object> Cache {
43 cache = new Dictionary<string, object> ();
48 public string MethodCalled { get; private set; }
50 public override object AddOrGetExisting (string key, object value, CacheItemPolicy policy, string regionName = null)
52 MethodCalled = "AddOrGetExisting (string key, object value, CacheItemPolicy policy, string regionName = null)";
53 if (String.IsNullOrEmpty (key) || value == null)
57 if (Cache.TryGetValue (key, out item))
60 Cache.Add (key, value);
64 public override CacheItem AddOrGetExisting (CacheItem value, CacheItemPolicy policy)
66 MethodCalled = "AddOrGetExisting (CacheItem value, CacheItemPolicy policy)";
71 if (Cache.TryGetValue (value.Key, out item))
72 return item as CacheItem;
74 Cache.Add (value.Key, value);
78 public override object AddOrGetExisting (string key, object value, DateTimeOffset absoluteExpiration, string regionName = null)
80 MethodCalled = "AddOrGetExisting (string key, object value, DateTimeOffset absoluteExpiration, string regionName = null)";
81 if (String.IsNullOrEmpty (key) || value == null)
85 if (Cache.TryGetValue (key, out item))
88 Cache.Add (key, value);
92 public override bool Contains (string key, string regionName = null)
94 throw new NotImplementedException ();
97 public override CacheEntryChangeMonitor CreateCacheEntryChangeMonitor (IEnumerable<string> keys, string regionName = null)
99 throw new NotImplementedException ();
102 public override DefaultCacheCapabilities DefaultCacheCapabilities
104 get { throw new NotImplementedException (); }
107 public override object Get (string key, string regionName = null)
109 throw new NotImplementedException ();
112 public override CacheItem GetCacheItem (string key, string regionName = null)
114 throw new NotImplementedException ();
117 public override long GetCount (string regionName = null)
119 throw new NotImplementedException ();
122 protected override IEnumerator<KeyValuePair<string, object>> GetEnumerator ()
124 throw new NotImplementedException ();
127 public override IDictionary<string, object> GetValues (IEnumerable<string> keys, string regionName = null)
129 MethodCalled = "IDictionary<string, object> GetValues (IEnumerable<string> keys, string regionName = null)";
130 var ret = new Dictionary<string, object> ();
134 Dictionary <string, object> cache = Cache;
135 if (cache.Count == 0)
139 foreach (string key in keys) {
140 if (!cache.TryGetValue (key, out value))
143 ret.Add (key, value);
149 public override string Name
151 get { throw new NotImplementedException (); }
154 public override object Remove (string key, string regionName = null)
156 throw new NotImplementedException ();
159 public override void Set (string key, object value, CacheItemPolicy policy, string regionName = null)
161 throw new NotImplementedException ();
164 public override void Set (CacheItem item, CacheItemPolicy policy)
166 throw new NotImplementedException ();
169 public override void Set (string key, object value, DateTimeOffset absoluteExpiration, string regionName = null)
171 throw new NotImplementedException ();
174 public override object this [string key]
178 throw new NotImplementedException ();
182 throw new NotImplementedException ();