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;
32 using System.Reflection;
35 namespace System.Runtime.Caching
37 public abstract class ObjectCache : IEnumerable<KeyValuePair<string, object>>, IEnumerable
39 static IServiceProvider host;
41 public static readonly DateTimeOffset InfiniteAbsoluteExpiration = DateTimeOffset.MaxValue;
42 public static readonly TimeSpan NoSlidingExpiration = TimeSpan.Zero;
44 public static IServiceProvider Host {
45 [TargetedPatchingOptOut ("Performance critical to inline this type of method across NGen image boundaries")]
49 throw new ArgumentNullException ("value");
52 throw new InvalidOperationException ("The property has already been set, and can only be set once.");
58 public abstract DefaultCacheCapabilities DefaultCacheCapabilities { get; }
59 public abstract object this [string key] { get; set; }
60 public abstract string Name { get; }
62 [TargetedPatchingOptOut ("Performance critical to inline this type of method across NGen image boundaries")]
63 protected ObjectCache ()
67 public virtual bool Add (CacheItem item, CacheItemPolicy policy)
69 return AddOrGetExisting (item, policy) == null;
72 public virtual bool Add (string key, object value, CacheItemPolicy policy, string regionName = null)
74 return AddOrGetExisting (key, value, policy, regionName) == null;
77 public virtual bool Add (string key, object value, DateTimeOffset absoluteExpiration, string regionName = null)
79 return AddOrGetExisting (key, value, absoluteExpiration, regionName) == null;
82 public abstract CacheItem AddOrGetExisting (CacheItem value, CacheItemPolicy policy);
83 public abstract object AddOrGetExisting (string key, object value, CacheItemPolicy policy, string regionName = null);
84 public abstract object AddOrGetExisting (string key, object value, DateTimeOffset absoluteExpiration, string regionName = null);
85 public abstract bool Contains (string key, string regionName = null);
86 public abstract CacheEntryChangeMonitor CreateCacheEntryChangeMonitor (IEnumerable <string> keys, string regionName = null);
87 public abstract object Get (string key, string regionName = null);
88 public abstract CacheItem GetCacheItem (string key, string regionName = null);
89 public abstract long GetCount (string regionName = null);
90 protected abstract IEnumerator <KeyValuePair <string, object>> GetEnumerator ();
91 public abstract IDictionary <string, object> GetValues (IEnumerable <string> keys, string regionName = null);
93 [TargetedPatchingOptOut ("Performance critical to inline this type of method across NGen image boundaries")]
94 public virtual IDictionary <string, object> GetValues (string regionName = null, params string[] keys)
96 return GetValues (keys.AsEnumerable <string> (), regionName);
99 public abstract object Remove (string key, string regionName = null);
100 public abstract void Set (CacheItem item, CacheItemPolicy policy);
101 public abstract void Set (string key, object value, CacheItemPolicy policy, string regionName = null);
102 public abstract void Set (string key, object value, DateTimeOffset absoluteExpiration, string regionName = null);
104 [TargetedPatchingOptOut ("Performance critical to inline this type of method across NGen image boundaries")]
105 IEnumerator <KeyValuePair <string,object>> IEnumerable<KeyValuePair<string, object>>.GetEnumerator ()
107 return GetEnumerator ();
110 IEnumerator IEnumerable.GetEnumerator ()
112 return GetEnumerator ();