referencesource files are used instead of the removed files.
+++ /dev/null
-//
-// CachingSectionGroup.cs
-//
-// Authors:
-// Marek Habersack <mhabersack@novell.com>
-//
-// Copyright (C) 2010 Novell, Inc. (http://novell.com/)
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-using System;
-using System.Configuration;
-
-namespace System.Runtime.Caching.Configuration
-{
- public sealed class CachingSectionGroup : ConfigurationSectionGroup
- {
- [ConfigurationProperty ("memoryCache")]
- public MemoryCacheSection MemoryCaches {
- get { return Sections ["memoryCache"] as MemoryCacheSection; }
- }
-
- public CachingSectionGroup ()
- {
- }
- }
-}
+++ /dev/null
-2010-04-24 Marek Habersack <mhabersack@novell.com>
-
- * MemoryCacheSettingsCollection.cs: added and implemented methods
- which appeared in .NET 4.0 final.
-
+++ /dev/null
-//
-// MemoryCacheElement.cs
-//
-// Authors:
-// Marek Habersack <mhabersack@novell.com>
-//
-// Copyright (C) 2010 Novell, Inc. (http://novell.com/)
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-using System;
-using System.ComponentModel;
-using System.Configuration;
-
-namespace System.Runtime.Caching.Configuration
-{
- public sealed class MemoryCacheElement : ConfigurationElement
- {
- static ConfigurationProperty cacheMemoryLimitMegabytesProp;
- static ConfigurationProperty nameProp;
- static ConfigurationProperty physicalMemoryLimitPercentageProp;
- static ConfigurationProperty pollingIntervalProp;
- static ConfigurationPropertyCollection properties;
-
- [ConfigurationProperty ("cacheMemoryLimitMegabytes", DefaultValue = 0)]
- [IntegerValidator (MinValue = 1)]
- public int CacheMemoryLimitMegabytes {
- get { return (int) base [cacheMemoryLimitMegabytesProp]; }
- set { base [cacheMemoryLimitMegabytesProp] = value; }
- }
-
- [ConfigurationProperty ("name", DefaultValue = "", IsRequired = true, IsKey = true)]
- [TypeConverter (typeof(WhiteSpaceTrimStringConverter))]
- [StringValidator (MinLength = 1)]
- public string Name {
- get { return (string) base [nameProp]; }
- set { base [nameProp] = value; }
- }
-
- [ConfigurationProperty ("physicalMemoryLimitPercentage", DefaultValue = 0)]
- [IntegerValidator (MinValue = 1, MaxValue = 100)]
- public int PhysicalMemoryLimitPercentage {
- get { return (int) base [physicalMemoryLimitPercentageProp]; }
- set { base [physicalMemoryLimitPercentageProp] = value; }
- }
-
- [ConfigurationProperty ("pollingInterval", DefaultValue = "00:02:00")]
- [TypeConverter (typeof(InfiniteTimeSpanConverter))]
- public TimeSpan PollingInterval {
- get { return (TimeSpan) base [pollingIntervalProp]; }
- set { base [pollingIntervalProp] = value; }
- }
-
- protected override ConfigurationPropertyCollection Properties {
- get { return properties; }
- }
-
- static MemoryCacheElement ()
- {
- cacheMemoryLimitMegabytesProp = new ConfigurationProperty ("cacheMemoryLimitMegabytes", typeof (int), 0,
- TypeDescriptor.GetConverter (typeof (int)),
- new IntegerValidator (1, Int32.MaxValue),
- ConfigurationPropertyOptions.None);
- nameProp = new ConfigurationProperty ("name", typeof (string), String.Empty,
- TypeDescriptor.GetConverter (typeof (string)),
- new NullableStringValidator (1),
- ConfigurationPropertyOptions.IsKey | ConfigurationPropertyOptions.IsRequired);
- physicalMemoryLimitPercentageProp = new ConfigurationProperty ("physicalMemoryLimitPercentage", typeof (int), 0,
- TypeDescriptor.GetConverter (typeof (int)),
- new IntegerValidator (1, 100),
- ConfigurationPropertyOptions.None);
- pollingIntervalProp = new ConfigurationProperty ("pollingInterval", typeof (TimeSpan), TimeSpan.FromMinutes (2),
- new InfiniteTimeSpanConverter (),
- new DefaultValidator (),
- ConfigurationPropertyOptions.None);
-
- properties = new ConfigurationPropertyCollection ();
- properties.Add (cacheMemoryLimitMegabytesProp);
- properties.Add (nameProp);
- properties.Add (physicalMemoryLimitPercentageProp);
- properties.Add (pollingIntervalProp);
- }
-
- internal MemoryCacheElement ()
- {
- }
-
- public MemoryCacheElement (string name)
- {
- this.Name = name;
- }
- }
-}
+++ /dev/null
-//
-// MemoryCacheSection.cs
-//
-// Authors:
-// Marek Habersack <mhabersack@novell.com>
-//
-// Copyright (C) 2010 Novell, Inc. (http://novell.com/)
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-using System;
-using System.Configuration;
-
-namespace System.Runtime.Caching.Configuration
-{
- public sealed class MemoryCacheSection : ConfigurationSection
- {
- static ConfigurationProperty namedCachesProp;
- static ConfigurationPropertyCollection properties;
-
- static MemoryCacheSection ()
- {
- namedCachesProp = new ConfigurationProperty ("namedCaches", typeof (MemoryCacheSettingsCollection), null);
-
- properties = new ConfigurationPropertyCollection ();
- properties.Add (namedCachesProp);
- }
-
- public MemoryCacheSection ()
- {
- }
-
- [ConfigurationProperty ("namedCaches")]
- public MemoryCacheSettingsCollection NamedCaches {
- get { return base [namedCachesProp] as MemoryCacheSettingsCollection; }
- }
-
- protected override ConfigurationPropertyCollection Properties {
- get { return properties; }
- }
- }
-}
+++ /dev/null
-//
-// MemoryCacheSettingsCollection.cs
-//
-// Authors:
-// Marek Habersack <mhabersack@novell.com>
-//
-// Copyright (C) 2010 Novell, Inc. (http://novell.com/)
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-using System;
-using System.Configuration;
-
-namespace System.Runtime.Caching.Configuration
-{
- [ConfigurationCollection (typeof(MemoryCacheElement), CollectionType = ConfigurationElementCollectionType.AddRemoveClearMap)]
- public sealed class MemoryCacheSettingsCollection : ConfigurationElementCollection
- {
- static ConfigurationPropertyCollection properties;
-
- public override ConfigurationElementCollectionType CollectionType {
- get { return ConfigurationElementCollectionType.AddRemoveClearMap; }
- }
-
- public MemoryCacheElement this[int index] {
- get { return BaseGet (index) as MemoryCacheElement; }
- set {
- if (BaseGet (index) != null)
- BaseRemoveAt (index);
- BaseAdd (index, value);
- }
- }
-
- public new MemoryCacheElement this[string key] {
- get {
- foreach (MemoryCacheElement mce in this) {
- if (String.Compare (key, mce.Name, StringComparison.Ordinal) == 0)
- return mce;
- }
-
- return null;
- }
- }
-
- protected override ConfigurationPropertyCollection Properties {
- get { return properties; }
- }
-
- static MemoryCacheSettingsCollection ()
- {
- properties = new ConfigurationPropertyCollection ();
- }
-
- public MemoryCacheSettingsCollection ()
- {
- }
-
- public void Add (MemoryCacheElement cache)
- {
- BaseAdd (cache);
- }
-
- public void Clear ()
- {
- BaseClear ();
- }
-
- protected override ConfigurationElement CreateNewElement ()
- {
- return new MemoryCacheElement ();
- }
-
- protected override ConfigurationElement CreateNewElement (string elementName)
- {
- return new MemoryCacheElement (elementName);
- }
-
- protected override object GetElementKey (ConfigurationElement element)
- {
- if (element == null)
- return null;
-
- return ((MemoryCacheElement)element).Name;
- }
-
- public int IndexOf (MemoryCacheElement cache)
- {
- if (cache == null)
- return -1;
-
- return BaseIndexOf (cache);
- }
-
- public void Remove (MemoryCacheElement cache)
- {
- if (cache == null)
- return;
-
- BaseRemove (GetElementKey (cache));
- }
-
- public void RemoveAt (int index)
- {
- BaseRemoveAt (index);
- }
- }
-}
+++ /dev/null
-//
-// IApplicationIdentifier.cs
-//
-// Authors:
-// Marek Habersack <mhabersack@novell.com>
-//
-// Copyright (C) 2010 Novell, Inc. (http://novell.com/)
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-using System;
-
-namespace System.Runtime.Caching.Hosting
-{
- public interface IApplicationIdentifier
- {
- string GetApplicationId ();
- }
-}
+++ /dev/null
-//
-// IFileChangeNotificationSystem.cs
-//
-// Authors:
-// Marek Habersack <mhabersack@novell.com>
-//
-// Copyright (C) 2010 Novell, Inc. (http://novell.com/)
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-using System;
-
-namespace System.Runtime.Caching.Hosting
-{
- public interface IFileChangeNotificationSystem
- {
- void StartMonitoring (string filePath, OnChangedCallback onChangedCallback, out object state, out DateTimeOffset lastWriteTime, out long fileSize);
- void StopMonitoring (string filePath, object state);
- }
-}
+++ /dev/null
-//
-// IMemoryCacheManager.cs
-//
-// Authors:
-// Marek Habersack <mhabersack@novell.com>
-//
-// Copyright (C) 2010 Novell, Inc. (http://novell.com/)
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-using System;
-using System.Runtime.Caching;
-
-namespace System.Runtime.Caching.Hosting
-{
- public interface IMemoryCacheManager
- {
- void ReleaseCache (MemoryCache cache);
- void UpdateCacheSize (long size, MemoryCache cache);
- }
-}
+++ /dev/null
-//
-// CacheEntryChangeMonitor.cs
-//
-// Authors:
-// Marek Habersack <mhabersack@novell.com>
-//
-// Copyright (C) 2010 Novell, Inc. (http://novell.com/)
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-using System;
-using System.Collections.ObjectModel;
-
-namespace System.Runtime.Caching
-{
- public abstract class CacheEntryChangeMonitor : ChangeMonitor
- {
- public abstract ReadOnlyCollection<string> CacheKeys { get; }
- public abstract DateTimeOffset LastModified { get; }
- public abstract string RegionName { get; }
-
- protected CacheEntryChangeMonitor ()
- {
- }
- }
-}
+++ /dev/null
-//
-// CacheEntryRemovedArguments.cs
-//
-// Authors:
-// Marek Habersack <mhabersack@novell.com>
-//
-// Copyright (C) 2010 Novell, Inc. (http://novell.com/)
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-using System;
-
-namespace System.Runtime.Caching
-{
- public class CacheEntryRemovedArguments
- {
- public CacheItem CacheItem { get; private set; }
- public CacheEntryRemovedReason RemovedReason { get; private set; }
- public ObjectCache Source { get; private set; }
-
- public CacheEntryRemovedArguments (ObjectCache source, CacheEntryRemovedReason reason, CacheItem cacheItem)
- {
- if (source == null)
- throw new ArgumentNullException ("source");
-
- if (cacheItem == null)
- throw new ArgumentNullException ("cacheItem");
-
- this.CacheItem = cacheItem;
- this.RemovedReason = reason;
- this.Source = source;
- }
- }
-}
+++ /dev/null
-//
-// CacheEntryRemovedCallback.cs
-//
-// Authors:
-// Marek Habersack <mhabersack@novell.com>
-//
-// Copyright (C) 2010 Novell, Inc. (http://novell.com/)
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-using System;
-
-namespace System.Runtime.Caching
-{
- public delegate void CacheEntryRemovedCallback (CacheEntryRemovedArguments arguments);
-}
+++ /dev/null
-//
-// CacheEntryRemoveReason.cs
-//
-// Authors:
-// Marek Habersack <mhabersack@novell.com>
-//
-// Copyright (C) 2010 Novell, Inc. (http://novell.com/)
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-using System;
-
-namespace System.Runtime.Caching
-{
- public enum CacheEntryRemovedReason
- {
- Removed,
- Expired,
- Evicted,
- ChangeMonitorChanged,
- CacheSpecificEviction
- }
-}
+++ /dev/null
-//
-// CacheEntryUpdateArguments.cs
-//
-// Authors:
-// Marek Habersack <mhabersack@novell.com>
-//
-// Copyright (C) 2010 Novell, Inc. (http://novell.com/)
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-using System;
-
-namespace System.Runtime.Caching
-{
- public class CacheEntryUpdateArguments
- {
- public string Key { get; private set; }
- public string RegionName { get; private set; }
- public CacheEntryRemovedReason RemovedReason { get; private set; }
- public ObjectCache Source { get; private set; }
- public CacheItem UpdatedCacheItem { get; set; }
- public CacheItemPolicy UpdatedCacheItemPolicy { get; set; }
-
- public CacheEntryUpdateArguments (ObjectCache source, CacheEntryRemovedReason reason, string key, string regionName)
- {
- if (source == null)
- throw new ArgumentNullException ("source");
-
- if (key == null)
- throw new ArgumentNullException ("key");
-
- this.Key = key;
- this.RegionName = regionName;
- this.RemovedReason = reason;
- this.Source = source;
- }
- }
-}
+++ /dev/null
-//
-// CacheEntryUpdateCallback.cs
-//
-// Authors:
-// Marek Habersack <mhabersack@novell.com>
-//
-// Copyright (C) 2010 Novell, Inc. (http://novell.com/)
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-using System;
-
-namespace System.Runtime.Caching
-{
- public delegate void CacheEntryUpdateCallback (CacheEntryUpdateArguments arguments);
-}
+++ /dev/null
-//
-// CacheItem.cs
-//
-// Authors:
-// Marek Habersack <mhabersack@novell.com>
-//
-// Copyright (C) 2010 Novell, Inc. (http://novell.com/)
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-using System;
-
-namespace System.Runtime.Caching
-{
- public class CacheItem
- {
- public string Key { get; set; }
- public string RegionName { get; set; }
- public object Value { get; set; }
-
- public CacheItem (string key) : this (key, null, null)
- {
- }
-
- public CacheItem (string key, object value) : this (key, value, null)
- {
- }
-
- public CacheItem (string key, object value, string regionName)
- {
- this.Key = key;
- this.RegionName = regionName;
- this.Value = value;
- }
- }
-}
+++ /dev/null
-//
-// CacheItemPolicy.cs
-//
-// Authors:
-// Marek Habersack <mhabersack@novell.com>
-//
-// Copyright (C) 2010 Novell, Inc. (http://novell.com/)
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-using System;
-using System.Collections.ObjectModel;
-
-namespace System.Runtime.Caching
-{
- public class CacheItemPolicy
- {
- Collection<ChangeMonitor> changeMonitors;
-
- public DateTimeOffset AbsoluteExpiration { get; set; }
-
- public Collection<ChangeMonitor> ChangeMonitors {
- get {
- if (changeMonitors == null)
- changeMonitors = new Collection <ChangeMonitor> ();
-
- return changeMonitors;
- }
- }
-
- public CacheItemPriority Priority { get; set; }
- public CacheEntryRemovedCallback RemovedCallback { get; set; }
- public TimeSpan SlidingExpiration { get; set; }
- public CacheEntryUpdateCallback UpdateCallback { get; set; }
-
- public CacheItemPolicy ()
- {
- this.AbsoluteExpiration = ObjectCache.InfiniteAbsoluteExpiration;
- this.Priority = CacheItemPriority.Default;
- this.SlidingExpiration = ObjectCache.NoSlidingExpiration;
- }
- }
-}
+++ /dev/null
-//
-// CacheItemPriority.cs
-//
-// Authors:
-// Marek Habersack <mhabersack@novell.com>
-//
-// Copyright (C) 2010 Novell, Inc. (http://novell.com/)
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-using System;
-
-namespace System.Runtime.Caching
-{
- public enum CacheItemPriority
- {
- Default,
- NotRemovable
- }
-}
+++ /dev/null
-2010-04-26 Marek Habersack <mhabersack@novell.com>
-
- * MemoryCacheLRU.cs: added
-
- * MemoryCacheContainer.cs: added LRU entry cache.
-
- * MemoryCache.cs: added option to emulate one CPU on SMP machines
- (for testing purposes) - "__MonoEmulateOneCPU"
-
-2010-04-24 Marek Habersack <mhabersack@novell.com>
-
- * ObjectCache.cs: implemented all the non-abstract methods.
-
- * MemoryCacheContainer.cs, MemoryCacheEntry.cs,
- MemoryCacheEntryChangeMonitor.cs,
- MemoryCacheEntryPriorityQueue.cs,
- MemoryCachePerformanceCounters.cs: added
-
- * MemoryCache.cs: implemented physical memory size detection, item
- expiration timer, indexer, reading of configuration values from
- config files, cache memory limit calculation, the
- AddOrGetExisting, Set, Get, Contains,
- CreateCacheEntryChangeMonitor, Dispose, GetCacheItem, GetCount,
- GetEnumerator, GetValues, Remove and Trim methods.
- Implemented support for per-cpu item containers.
- Modified parameters of several methods to match .NET 4.0 release.
-
- * HostFileChangeMonitor.cs: implemented according to tests.
-
- * Helpers.cs: added new properties, StringComparer and Is64bit
-
- * FileChangeNotificationSystemEntry.cs: added
-
- * FileChangeNotificationSystem.cs: implemented
-
- * ChangeMonitor.cs: NotifyOnChanged now properly throws an
- exception if it was called more than once.
-
- * CacheEntryRemovedReason.cs: renamed from
- CacheEntryRemoveReason.cs
-
- * CacheEntryChangeMonitor.cs: renamed from CacheEntryMonitor.cs
-
+++ /dev/null
-//
-// ChangeMonitor.cs
-//
-// Authors:
-// Marek Habersack <mhabersack@novell.com>
-//
-// Copyright (C) 2010 Novell, Inc. (http://novell.com/)
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-using System;
-
-namespace System.Runtime.Caching
-{
- public abstract class ChangeMonitor : IDisposable
- {
- bool initializationComplete;
- bool notifyOnChangedCalled;
- OnChangedCallback onChangedCallback;
- object onChangedState;
-
- public bool HasChanged { get; private set; }
- public bool IsDisposed { get; private set; }
- public abstract string UniqueId { get; }
-
- protected ChangeMonitor ()
- {
- }
-
- public void Dispose ()
- {
- if (IsDisposed)
- return;
-
- if (!initializationComplete)
- // TODO: check if Dispose (bool) is called in this case
- throw new InvalidOperationException ("Initialization is not complete in the derived change-monitor class that called the base Dispose method.");
-
- try {
- try {
- InvokeOnChangedCallback (onChangedState);
- } catch {
- // ignore
- // TODO: check what happens if the callback throws an exception - is
- // Dispose (true) called then?
- }
-
- Dispose (true);
- } finally {
- IsDisposed = true;
- }
- }
-
- protected abstract void Dispose (bool disposing);
-
- protected void InitializationComplete ()
- {
- initializationComplete = true;
- if (HasChanged)
- Dispose ();
- }
-
- void InvokeOnChangedCallback (object state)
- {
- if (onChangedCallback == null)
- return;
-
- try {
- onChangedCallback (state);
- } finally {
- onChangedCallback = null;
- onChangedState = null;
- }
- }
-
- public void NotifyOnChanged (OnChangedCallback onChangedCallback)
- {
- if (onChangedCallback == null)
- throw new ArgumentNullException ("onChangedCallback");
-
- if (notifyOnChangedCalled)
- throw new InvalidOperationException ("The callback method has already been invoked.");
-
- notifyOnChangedCalled = true;
- this.onChangedCallback = onChangedCallback;
- if (HasChanged) {
- InvokeOnChangedCallback (onChangedState);
- return;
- }
-
- }
-
- protected void OnChanged (object state)
- {
- HasChanged = true;
- try {
- if (onChangedCallback == null)
- onChangedState = state;
- else
- InvokeOnChangedCallback (state);
- } catch {
- // ignore
- // TODO: check what happens if callback throws an exception - is
- // Dispose below called?
- } finally {
- if (initializationComplete)
- Dispose ();
- }
- }
- }
-}
+++ /dev/null
-//
-// DefaultCacheCapabilities.cs
-//
-// Authors:
-// Marek Habersack <mhabersack@novell.com>
-//
-// Copyright (C) 2010 Novell, Inc. (http://novell.com/)
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-using System;
-
-namespace System.Runtime.Caching
-{
- [Flags]
- public enum DefaultCacheCapabilities
- {
- None = 0x00,
- InMemoryProvider = 0x01,
- OutOfProcessProvider = 0x02,
- CacheEntryChangeMonitors = 0x04,
- AbsoluteExpirations = 0x08,
- SlidingExpirations = 0x10,
- CacheEntryUpdateCallback = 0x20,
- CacheEntryRemovedCallback = 0x40,
- CacheRegions = 0x80
- }
-}
+++ /dev/null
-//
-// FileChangeMonitor.cs
-//
-// Authors:
-// Marek Habersack <mhabersack@novell.com>
-//
-// Copyright (C) 2010 Novell, Inc. (http://novell.com/)
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-using System;
-using System.Collections.ObjectModel;
-
-namespace System.Runtime.Caching
-{
- public abstract class FileChangeMonitor : ChangeMonitor
- {
- public abstract ReadOnlyCollection<string> FilePaths { get; }
- public abstract DateTimeOffset LastModified { get; }
-
- protected FileChangeMonitor ()
- {
- }
- }
-}
+++ /dev/null
-//
-// FileChangeNotificationSystem.cs
-//
-// Authors:
-// Marek Habersack <mhabersack@novell.com>
-//
-// Copyright (C) 2010 Novell, Inc. (http://novell.com/)
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Runtime.Caching.Hosting;
-using System.Text;
-
-namespace System.Runtime.Caching
-{
- sealed class FileChangeNotificationSystem : IFileChangeNotificationSystem, IDisposable
- {
- static readonly object watchers_lock = new object ();
-
- Dictionary <string, FileChangeNotificationSystemEntry> watchers;
- OnChangedCallback callback;
-
- Dictionary <string, FileChangeNotificationSystemEntry> Watchers {
- get {
- if (watchers == null)
- watchers = new Dictionary <string, FileChangeNotificationSystemEntry> (Helpers.StringEqualityComparer);
-
- return watchers;
- }
- }
-
- public void StartMonitoring (string filePath, OnChangedCallback onChangedCallback, out object state, out DateTimeOffset lastWriteTime, out long fileSize)
- {
- if (String.IsNullOrEmpty (filePath))
- throw new ArgumentNullException ("filePath");
-
- callback = onChangedCallback;
-
- string parentDir;
- if (File.Exists (filePath)) {
- var fi = new FileInfo (filePath);
- lastWriteTime = DateTimeOffset.FromFileTime (fi.LastWriteTimeUtc.Ticks);
- fileSize = fi.Length;
- parentDir = Path.GetDirectoryName (filePath);
- } else if (Directory.Exists (filePath)) {
- var di = new DirectoryInfo (filePath);
- lastWriteTime = DateTimeOffset.FromFileTime (di.LastWriteTimeUtc.Ticks);
- fileSize = -1L;
- parentDir = filePath;
- } else {
- lastWriteTime = DateTimeOffset.MaxValue;
- fileSize = -1L;
-
- if (filePath.LastIndexOf (Path.DirectorySeparatorChar) != -1)
- parentDir = Path.GetDirectoryName (filePath);
- else
- parentDir = filePath;
- }
-
- FileChangeNotificationSystemEntry entry;
- lock (watchers_lock) {
- Dictionary <string, FileChangeNotificationSystemEntry> watchers = Watchers;
-
- if (!watchers.TryGetValue (parentDir, out entry)) {
- entry = new FileChangeNotificationSystemEntry (parentDir, this);
- watchers.Add (parentDir, entry);
- }
-
- entry.Add (filePath);
- entry.Start ();
- }
-
- state = entry;
- }
-
- public void StopMonitoring (string filePath, object state)
- {
- if (String.IsNullOrEmpty (filePath))
- return;
-
- var entry = state as FileChangeNotificationSystemEntry;
- if (entry == null)
- return;
-
- lock (watchers_lock) {
- entry.Remove (filePath);
- if (entry.IsEmpty) {
- if (watchers != null && watchers.ContainsKey (filePath))
- watchers.Remove (filePath);
-
- entry.Stop ();
- entry.Dispose ();
- }
- }
- }
-
- public void OnChanged (WatcherChangeTypes changeType, string filePath, string newFilePath)
- {
- if (callback == null)
- return;
-
- FileChangeNotificationSystemEntry entry;
-
- if (watchers == null || !watchers.TryGetValue (filePath, out entry))
- entry = null;
-
- callback (entry);
- }
-
- public void Dispose ()
- {
- lock (watchers_lock) {
- if (watchers == null || watchers.Count == 0)
- return;
-
- FileChangeNotificationSystemEntry entry;
- foreach (var de in watchers) {
- entry = de.Value;
- if (entry == null)
- continue;
-
- entry.Stop ();
- entry.Dispose ();
- }
-
- watchers.Clear ();
- }
- }
-
- void IDisposable.Dispose ()
- {
- Dispose ();
- }
- }
-}
+++ /dev/null
-//
-// FileChangeNotificationSystemEntry.cs
-//
-// Authors:
-// Marek Habersack <mhabersack@novell.com>
-//
-// Copyright (C) 2010 Novell, Inc. (http://novell.com/)
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Runtime.Caching.Hosting;
-using System.Text;
-
-namespace System.Runtime.Caching
-{
- // This class is NOT thread-safe - the caller needs to assure access serialization when
- // calling Add/Remove
- sealed class FileChangeNotificationSystemEntry : IDisposable
- {
- string watchedDirPath;
- FileChangeNotificationSystem owner;
- FileSystemWatcher watcher;
- SortedDictionary <string, bool> filePaths;
-
- SortedDictionary <string, bool> FilePaths {
- get {
- if (filePaths == null)
- filePaths = new SortedDictionary <string, bool> (Helpers.StringComparer);
- return filePaths;
- }
- }
-
- public bool IsEmpty {
- get { return (filePaths == null || filePaths.Count == 0); }
- }
-
- public FileChangeNotificationSystemEntry (string dirPath, FileChangeNotificationSystem owner)
- {
- if (String.IsNullOrEmpty (dirPath))
- throw new ArgumentNullException ("dirPath");
-
- if (owner == null)
- throw new ArgumentNullException ("owner");
-
- watchedDirPath = dirPath;
- this.owner = owner;
- }
-
- public void Add (string filePath)
- {
- if (String.IsNullOrEmpty (filePath))
- return;
-
- bool start = false;
- try {
- if (watcher == null) {
- watcher = new FileSystemWatcher (watchedDirPath);
- watcher.IncludeSubdirectories = false;
- watcher.Filter = String.Empty;
- watcher.NotifyFilter = NotifyFilters.FileName |
- NotifyFilters.DirectoryName |
- NotifyFilters.Size |
- NotifyFilters.LastWrite |
- NotifyFilters.CreationTime;
- watcher.Changed += OnChanged;
- watcher.Created += OnChanged;
- watcher.Deleted += OnChanged;
- watcher.Renamed += OnRenamed;
- } else if (watcher.EnableRaisingEvents) {
- Stop ();
- start = true;
- }
-
- SortedDictionary <string, bool> filePaths = FilePaths;
- if (filePaths.ContainsKey (filePath))
- return;
-
- filePaths.Add (filePath, true);
- } finally {
- if (start)
- Start ();
- }
- }
-
- public void Remove (string filePath)
- {
- if (filePath == null)
- return;
-
- bool start = false;
- try {
- if (watcher != null && watcher.EnableRaisingEvents) {
- Stop ();
- start = true;
- }
-
- SortedDictionary <string, bool> filePaths = FilePaths;
- if (!filePaths.ContainsKey (filePath))
- return;
-
- filePaths.Remove (filePath);
- } finally {
- if (start)
- Start ();
- }
- }
-
- public void Start ()
- {
- if (watcher == null)
- return;
-
- watcher.EnableRaisingEvents = true;
- }
-
- public void Stop ()
- {
- if (watcher == null)
- return;
-
- watcher.EnableRaisingEvents = false;
- }
-
- public void Dispose ()
- {
- if (watcher == null)
- return;
-
- try {
- Stop ();
- } finally {
- watcher.Dispose ();
- }
- }
-
- void IDisposable.Dispose ()
- {
- Dispose ();
- }
-
- void OnChanged (object source, FileSystemEventArgs e)
- {
- string fullPath = e.FullPath;
- if (owner == null || filePaths == null || !filePaths.ContainsKey (fullPath))
- return;
-
- owner.OnChanged (e.ChangeType, fullPath, null);
- }
-
- void OnRenamed (object source, RenamedEventArgs e)
- {
- string fullPath = e.FullPath;
- if (owner == null || filePaths == null || !filePaths.ContainsKey (fullPath))
- return;
-
- owner.OnChanged (e.ChangeType, e.OldFullPath, e.FullPath);
- }
- }
-}
+++ /dev/null
-//
-// ObjectCache.cs
-//
-// Authors:
-// Marek Habersack <mhabersack@novell.com>
-//
-// Copyright (C) 2010 Novell, Inc. (http://novell.com/)
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-using System;
-using System.Collections.Generic;
-
-namespace System.Runtime.Caching
-{
- static class Helpers
- {
- public static bool CaseInsensitive {
- get;
- private set;
- }
-
- public static bool Is64Bit {
- get;
- private set;
- }
-
- public static IEqualityComparer <string> StringEqualityComparer {
- get; private set;
- }
-
- public static IComparer <string> StringComparer {
- get; private set;
- }
-
- public static StringComparison StringComparison {
- get; private set;
- }
-
- static Helpers ()
- {
- PlatformID pid = Environment.OSVersion.Platform;
- bool runningOnWindows = ((int) pid != 128 && pid != PlatformID.Unix && pid != PlatformID.MacOSX);
-
- Is64Bit = IntPtr.Size == 8;
- if (runningOnWindows)
- CaseInsensitive = true;
- else {
- string mono_iomap = Environment.GetEnvironmentVariable ("MONO_IOMAP");
- if (!String.IsNullOrEmpty (mono_iomap)) {
- if (mono_iomap == "all")
- CaseInsensitive = true;
- else {
- string[] parts = mono_iomap.Split (':');
- foreach (string p in parts) {
- if (p == "all" || p == "case") {
- CaseInsensitive = true;
- break;
- }
- }
- }
- }
- }
-
- if (CaseInsensitive) {
- StringEqualityComparer = global::System.StringComparer.OrdinalIgnoreCase;
- StringComparer = global::System.StringComparer.OrdinalIgnoreCase;
- StringComparison = global::System.StringComparison.OrdinalIgnoreCase;
- } else {
- StringEqualityComparer = global::System.StringComparer.Ordinal;
- StringComparer = global::System.StringComparer.Ordinal;
- StringComparison = global::System.StringComparison.Ordinal;
-
- }
- }
- }
-}
+++ /dev/null
-//
-// HostFileChangeMonitor.cs
-//
-// Authors:
-// Marek Habersack <mhabersack@novell.com>
-//
-// Copyright (C) 2010 Novell, Inc. (http://novell.com/)
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-using System;
-using System.Collections.Generic;
-using System.Collections.ObjectModel;
-using System.IO;
-using System.Runtime.Caching.Hosting;
-using System.Text;
-
-namespace System.Runtime.Caching
-{
- public sealed class HostFileChangeMonitor : FileChangeMonitor
- {
- const long INVALID_FILE_SIZE = -1L;
- static readonly object notificationSystemLock = new object ();
- static readonly DateTime missingFileTimeStamp = new DateTime (0x701CE1722770000);
- static IFileChangeNotificationSystem notificationSystem;
- static bool notificationSystemSetFromHost;
-
- ReadOnlyCollection <string> filePaths;
- DateTime lastModified;
- string uniqueId;
- bool disposeNotificationSystem;
-
- Dictionary <string, object> notificationStates;
-
- public override ReadOnlyCollection<string> FilePaths {
- get { return filePaths;}
- }
-
- public override DateTimeOffset LastModified {
- get { return lastModified; }
- }
-
- public override string UniqueId {
- get { return uniqueId; }
- }
-
- public HostFileChangeMonitor (IList<string> filePaths)
- {
- if (filePaths == null)
- throw new ArgumentNullException ("filePaths");
-
- if (filePaths.Count == 0)
- throw new ArgumentException ("filePaths contains zero items.");
-
- var list = new List <string> (filePaths.Count);
- var sb = new StringBuilder ();
- lastModified = DateTime.MinValue;
- DateTime lastWrite;
- long size;
- bool ignoreForUniqueId;
-
- foreach (string p in filePaths) {
- if (String.IsNullOrEmpty (p))
- throw new ArgumentException ("A path in the filePaths list is null or an empty string.");
-
- if (!Path.IsPathRooted (p))
- throw new ArgumentException ("Absolute path information is required.");
-
- if (list.Contains (p))
- ignoreForUniqueId = true;
- else
- ignoreForUniqueId = false;
-
- list.Add (p);
-
- if (ignoreForUniqueId)
- continue;
-
- if (Directory.Exists (p)) {
- var di = new DirectoryInfo (p);
- lastWrite = di.LastWriteTimeUtc;
- size = INVALID_FILE_SIZE;
- } else if (File.Exists (p)) {
- var fi = new FileInfo (p);
- lastWrite = fi.LastWriteTimeUtc;
- size = fi.Length;
- } else {
- lastWrite = missingFileTimeStamp;
- size = INVALID_FILE_SIZE;
- }
-
- if (lastWrite > lastModified)
- lastModified = lastWrite;
-
- sb.AppendFormat ("{0}{1:X}{2:X}", p, lastWrite.Ticks, (ulong)size);
- }
-
- this.filePaths = new ReadOnlyCollection <string> (list);
- this.uniqueId = sb.ToString ();
-
- bool initComplete = false;
- try {
- InitMonitoring ();
- initComplete = true;
- } finally {
- InitializationComplete ();
- if (!initComplete)
- Dispose ();
- }
- }
-
- void InitMonitoring ()
- {
- IServiceProvider host;
- if (!notificationSystemSetFromHost && (host = ObjectCache.Host) != null) {
- lock (notificationSystemLock) {
- if (!notificationSystemSetFromHost) {
- if (host != null)
- notificationSystem = host.GetService (typeof (IFileChangeNotificationSystem)) as IFileChangeNotificationSystem;
-
- if (notificationSystem != null)
- notificationSystemSetFromHost = true;
- }
- }
- }
-
- if (!notificationSystemSetFromHost) {
- notificationSystem = new FileChangeNotificationSystem ();
- disposeNotificationSystem = true;
- }
-
- object state;
-
- // TODO: what are these two used for?
- DateTimeOffset lastWriteTime;
- long fileSize;
-
- notificationStates = new Dictionary <string, object> (filePaths.Count, Helpers.StringEqualityComparer);
- foreach (string path in filePaths) {
- if (notificationStates.ContainsKey (path))
- continue; // silently ignore dupes
-
- notificationSystem.StartMonitoring (path, OnChanged, out state, out lastWriteTime, out fileSize);
- notificationStates.Add (path, state);
- }
- }
-
- protected override void Dispose (bool disposing)
- {
- if (disposing && notificationSystem != null) {
- object state;
-
- foreach (var de in notificationStates) {
- state = de.Value;
- if (state == null)
- continue;
-
- try {
- notificationSystem.StopMonitoring (de.Key, state);
- } catch {
- // ignore
- }
- }
-
- if (disposeNotificationSystem) {
- var fcns = notificationSystem as FileChangeNotificationSystem;
- if (fcns != null) {
- try {
- fcns.Dispose ();
- } finally {
- notificationSystem = null;
- }
- }
- }
- }
- }
- }
-}
+++ /dev/null
-//
-// MemoryCache.cs
-//
-// Authors:
-// Marek Habersack <mhabersack@novell.com>
-//
-// Copyright (C) 2010 Novell, Inc. (http://novell.com/)
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-using System;
-using System.Collections;
-using System.Collections.Generic;
-using System.Collections.Specialized;
-using System.Configuration;
-using System.Diagnostics;
-using System.Reflection;
-using System.Runtime.Caching.Configuration;
-using System.Threading;
-
-namespace System.Runtime.Caching
-{
- public class MemoryCache : ObjectCache, IEnumerable, IDisposable
- {
- const long DEFAULT_TIMER_PERIOD = 20000; // .NET's default, ms
-
- static long totalPhysicalMemory;
- static int numCPUs;
-
- string name;
- MemoryCacheContainer[] containers;
- DefaultCacheCapabilities defaultCaps;
- MemoryCachePerformanceCounters perfCounters;
- bool noPerformanceCounters;
- bool emulateOneCPU;
-
- static ulong TotalPhysicalMemory {
- get {
- if (totalPhysicalMemory == 0)
- DetermineTotalPhysicalMemory ();
-
- return (ulong)totalPhysicalMemory;
- }
- }
-
- internal long TimerPeriod {
- get; private set;
- }
-
- public static MemoryCache Default { get; private set; }
-
- // LAMESPEC: this value is represented in bytes, not megabytes
- public long CacheMemoryLimit { get; private set; }
-
- public override DefaultCacheCapabilities DefaultCacheCapabilities {
- get { return defaultCaps; }
- }
-
- public override object this [string key] {
- get { return FindContainer (key).Get (key); }
- set { Set (key, value, ObjectCache.InfiniteAbsoluteExpiration); }
- }
-
- public override string Name {
- get { return name; }
- }
-
- public long PhysicalMemoryLimit { get; private set; }
- public TimeSpan PollingInterval { get; private set; }
-
- static MemoryCache ()
- {
- numCPUs = Environment.ProcessorCount;
- Default = new MemoryCache ();
- }
-
- MemoryCache ()
- {
- name = "Default";
- CommonInit (name);
- }
-
- public MemoryCache (string name, NameValueCollection config = null)
- {
- if (name == null)
- throw new ArgumentNullException ("name");
-
- if (name.Length == 0)
- throw new ArgumentException ("is an empty string.", "name");
-
- if (String.Compare (name, "default", StringComparison.OrdinalIgnoreCase) == 0)
- throw new ArgumentException ("'default' is a reserved name.", "name");
-
- this.name = name;
- CommonInit (name, config);
- }
-
- void CommonInit (string name, NameValueCollection config = null)
- {
- this.defaultCaps = DefaultCacheCapabilities.InMemoryProvider |
- DefaultCacheCapabilities.CacheEntryChangeMonitors |
- DefaultCacheCapabilities.AbsoluteExpirations |
- DefaultCacheCapabilities.SlidingExpirations |
- DefaultCacheCapabilities.CacheEntryRemovedCallback |
- DefaultCacheCapabilities.CacheEntryUpdateCallback;
-
- GetValuesFromConfig (name, config);
- containers = new MemoryCacheContainer [numCPUs];
- perfCounters = new MemoryCachePerformanceCounters (name.ToLowerInvariant (), noPerformanceCounters);
- }
-
- static void DetermineTotalPhysicalMemory ()
- {
- var pc = new PerformanceCounter ("Mono Memory", "Total Physical Memory");
- long memBytes = pc.RawValue;
-
- if (memBytes == 0)
- memBytes = 134217728L; // 128MB, the runtime default when it's
- // impossible to determine the physical
- // memory size
-
- Interlocked.CompareExchange (ref totalPhysicalMemory, memBytes, 0);
- }
-
- bool ParseBoolConfigValue (string paramName, string name, NameValueCollection config, bool doTrow)
- {
- string value = config [name];
- if (String.IsNullOrEmpty (value))
- return false;
-
- try {
- return Boolean.Parse (value);
- } catch {
- return false;
- }
- }
-
- bool ParseInt32ConfigValue (string paramName, string name, NameValueCollection config, int maxValue, bool doThrow, out int parsed)
- {
- parsed = -1;
- string value = config [name];
- if (String.IsNullOrEmpty (value))
- return false;
-
- try {
- parsed = (int)UInt32.Parse (value);
- } catch (Exception ex) {
- if (doThrow)
- throw new ArgumentException (
- String.Format ("Invalid configuration: {0}=\"{1}\". The {0} value must be a non-negative 32-bit integer", name, value),
- paramName,
- ex);
- return false;
- }
-
- if (parsed < 0 || (uint)parsed > (uint)maxValue) {
- if (doThrow)
- throw new ArgumentException (
- String.Format ("Invalid configuration: {0}=\"{1}\". The {0} value cannot be greater than '{2}'.", name, value, maxValue),
- paramName);
- return false;
- }
-
- return true;
- }
-
- bool ParseTimeSpanConfigValue (string paramName, string name, NameValueCollection config, out TimeSpan parsed)
- {
- string value = config [name];
- if (String.IsNullOrEmpty (value)) {
- parsed = TimeSpan.MinValue;
- return false;
- }
-
- try {
- parsed = TimeSpan.Parse (value);
- return true;
- } catch (Exception ex) {
- throw new ArgumentException (
- String.Format ("Invalid configuration: {0}=\"{1}\". The {0} value must be a time interval that can be parsed by System.TimeSpan.Parse", name, value),
- paramName,
- ex);
- }
- }
-
- void GetValuesFromConfig (string name, NameValueCollection config)
- {
- var mcs = ConfigurationManager.GetSection ("system.runtime.caching/memoryCache") as MemoryCacheSection;
- MemoryCacheSettingsCollection settings = mcs != null ? mcs.NamedCaches : null;
- MemoryCacheElement element = settings != null ? settings [name] : null;
-
- if (element != null && config == null) {
- CacheMemoryLimit = (long)element.CacheMemoryLimitMegabytes * 1048576L;
- PhysicalMemoryLimit = (long)element.PhysicalMemoryLimitPercentage;
- PollingInterval = element.PollingInterval;
- }
-
- if (config != null) {
- int parsed;
-
- if (ParseInt32ConfigValue ("config", "cacheMemoryLimitMegabytes", config, Int32.MaxValue, true, out parsed))
- CacheMemoryLimit = parsed * 1048576L;
- else if (element != null)
- CacheMemoryLimit = (long)element.CacheMemoryLimitMegabytes * 1048576L;
-
- if (ParseInt32ConfigValue ("config", "physicalMemoryLimitPercentage", config, 100, true, out parsed))
- PhysicalMemoryLimit = parsed;
- else if (element != null)
- PhysicalMemoryLimit = (long)element.PhysicalMemoryLimitPercentage;
-
- TimeSpan ts;
- if (ParseTimeSpanConfigValue ("config", "pollingInterval", config, out ts))
- PollingInterval = ts;
- else if (element != null)
- PollingInterval = element.PollingInterval;
-
- // Those are Mono-specific
- if (!String.IsNullOrEmpty (config ["__MonoDisablePerformanceCounters"]))
- noPerformanceCounters = true;
-
- if (ParseInt32ConfigValue ("config", "__MonoTimerPeriod", config, Int32.MaxValue, false, out parsed))
- TimerPeriod = (long)(parsed * 1000);
- else
- TimerPeriod = DEFAULT_TIMER_PERIOD;
-
- if (ParseBoolConfigValue ("config", "__MonoEmulateOneCPU", config, false))
- emulateOneCPU = true;
- } else
- TimerPeriod = DEFAULT_TIMER_PERIOD;
-
- if (CacheMemoryLimit == 0) {
- // Calculated using algorithm described in this blog entry:
- //
- // http://blogs.msdn.com/tmarq/archive/2007/06/25/some-history-on-the-asp-net-cache-memory-limits.aspx
- //
- ulong physicalRam = TotalPhysicalMemory;
- ulong maxCacheSize;
-
- // Determine the upper bound
- if (Helpers.Is64Bit)
- maxCacheSize = 0x10000000000UL; // 1TB
- else if (physicalRam > 0x80000000UL) // 2GB
- maxCacheSize = 0x70800000UL; // 1800MB
- else
- maxCacheSize = 0x32000000UL; // 800MB
-
- physicalRam = (physicalRam * 3) / 5; // 60%
- CacheMemoryLimit = (long)Math.Min (physicalRam, maxCacheSize);
- }
-
- if (PhysicalMemoryLimit == 0)
- PhysicalMemoryLimit = 98;
-
- if (PollingInterval == TimeSpan.Zero)
- PollingInterval = TimeSpan.FromMinutes (2);
- }
-
- public override CacheItem AddOrGetExisting (CacheItem item, CacheItemPolicy policy)
- {
- if (item == null)
- throw new ArgumentNullException ("item");
-
- string key = item.Key;
- return new CacheItem (key, DoAddOrGetExisting (key, item.Value, policy));
- }
-
- public override object AddOrGetExisting (string key, object value, CacheItemPolicy policy, string regionName = null)
- {
- if (regionName != null)
- throw new NotSupportedException ("The parameter regionName must be null.");
-
- return DoAddOrGetExisting (key, value, policy, regionName);
- }
-
- public override object AddOrGetExisting (string key, object value, DateTimeOffset absoluteExpiration, string regionName = null)
- {
- if (regionName != null)
- throw new NotSupportedException ("The parameter regionName must be null.");
-
- var policy = new CacheItemPolicy ();
- policy.AbsoluteExpiration = absoluteExpiration;
-
- return DoAddOrGetExisting (key, value, policy, regionName);
- }
-
- object DoAddOrGetExisting (string key, object value, CacheItemPolicy policy, string regionName = null)
- {
- if (key == null)
- throw new ArgumentNullException ("key");
-
- if (value == null)
- throw new ArgumentNullException ("value");
-
- if (policy != null) {
- ValidatePolicy (policy, false);
- if (policy.AbsoluteExpiration < DateTimeOffset.Now)
- return null;
- }
-
- return FindContainer (key).AddOrGetExisting (key, value, policy);
- }
-
- public override bool Contains (string key, string regionName = null)
- {
- if (key == null)
- throw new ArgumentNullException ("key");
-
- if (regionName != null)
- throw new NotSupportedException ("The parameter regionName must be null.");
-
- return FindContainer (key).ContainsKey (key);
- }
-
- public override CacheEntryChangeMonitor CreateCacheEntryChangeMonitor (IEnumerable <string> keys, string regionName = null)
- {
- if (regionName != null)
- throw new NotSupportedException ("The parameter regionName must be null.");
-
- if (keys == null)
- throw new ArgumentNullException ("keys");
-
- int count = 0;
- foreach (string key in keys) {
- if (key == null)
- throw new ArgumentException ("The collection 'keys' contains a null element.");
- count++;
- }
- if (count == 0)
- throw new ArgumentException ("The collection 'keys' is empty");
-
- return new MemoryCacheEntryChangeMonitor (this, keys);
- }
-
- public void Dispose ()
- {
- foreach (MemoryCacheContainer container in containers) {
- if (container == null)
- continue;
-
- container.Dispose ();
- }
-
- perfCounters.Dispose ();
- }
-
- MemoryCacheContainer FindContainer (string key)
- {
- if (key == null)
- throw new ArgumentNullException ("key");
-
- if (emulateOneCPU || numCPUs == 1) {
- if (containers [0] == null)
- containers [0] = new MemoryCacheContainer (this, 0, perfCounters);
-
- return containers [0];
- }
-
- int containerIdx = Math.Abs (key.GetHashCode () % numCPUs);
- if (containers [containerIdx] == null)
- containers [containerIdx] = new MemoryCacheContainer (this, containerIdx, perfCounters);
-
- return containers [containerIdx];
- }
-
- public override object Get (string key, string regionName = null)
- {
- if (regionName != null)
- throw new NotSupportedException ("The parameter regionName must be null.");
-
- if (key == null)
- throw new ArgumentNullException ("key");
-
- return FindContainer (key).Get (key);
- }
-
- internal MemoryCacheEntry GetEntry (string key)
- {
- return FindContainer (key).GetEntry (key);
- }
-
- public override CacheItem GetCacheItem (string key, string regionName = null)
- {
- if (regionName != null)
- throw new NotSupportedException ("The parameter regionName must be null.");
-
- if (key == null)
- throw new ArgumentNullException ("key");
-
- object value = Get (key);
- if (value == null)
- return null;
-
- return new CacheItem (key, value);
- }
-
- public override long GetCount (string regionName = null)
- {
- if (regionName != null)
- throw new NotSupportedException ("The parameter regionName must be null.");
-
- long ret = 0;
- MemoryCacheContainer container;
- for (int i = 0; i < numCPUs; i++) {
- container = containers [i];
- if (container == null)
- continue;
-
- ret += container.Count;
- }
-
- return ret;
- }
-
- protected override IEnumerator <KeyValuePair <string,object>> GetEnumerator ()
- {
- var dict = new Dictionary <string, object> ();
-
- CopyEntries (dict);
- return dict.GetEnumerator ();
- }
-
- public override IDictionary <string,object> GetValues (IEnumerable <string> keys, string regionName = null)
- {
- if (regionName != null)
- throw new NotSupportedException ("The parameter regionName must be null.");
-
- if (keys == null)
- throw new ArgumentNullException ("keys");
-
- MemoryCacheEntry entry;
- var ret = new Dictionary <string, object> ();
- foreach (string key in keys) {
- if (key == null)
- throw new ArgumentException ("The collection 'keys' contains a null element.");
-
- entry = GetEntry (key);
-
- // LAMESPEC: MSDN says the number of items in the returned dictionary should be the same as in the
- // 'keys' collection - this is not the case. The returned dictionary contains only entries for keys
- // that exist in the cache.
- if (entry == null)
- continue;
-
- ret.Add (key, entry.Value);
- }
-
- if (ret.Count == 0)
- return null;
-
- return ret;
- }
-
- public override object Remove (string key, string regionName = null)
- {
- if (regionName != null)
- throw new NotSupportedException ("The parameter regionName must be null.");
-
- if (key == null)
- throw new ArgumentNullException ("key");
-
- return FindContainer (key).Remove (key);
- }
-
- internal void Remove (MemoryCacheEntry entry)
- {
- if (entry == null)
- return;
-
- string key = entry.Key;
- FindContainer (key).Remove (key);
- }
-
- public override void Set (CacheItem item, CacheItemPolicy policy)
- {
- if (item == null)
- throw new ArgumentNullException ("item");
-
- Set (item.Key, item.Value, policy);
- }
-
- public override void Set (string key, object value, CacheItemPolicy policy, string regionName = null)
- {
- if (regionName != null)
- throw new NotSupportedException ("The parameter regionName must be null.");
-
- if (key == null)
- throw new ArgumentNullException ("key");
-
- if (value == null)
- throw new ArgumentNullException ("value");
-
- if (policy != null) {
- ValidatePolicy (policy, true);
- if (policy.AbsoluteExpiration < DateTimeOffset.Now)
- return;
- }
-
- FindContainer (key).Set (key, value, policy);
- }
-
- public override void Set (string key, object value, DateTimeOffset absoluteExpiration, string regionName = null)
- {
- var policy = new CacheItemPolicy ();
- policy.AbsoluteExpiration = absoluteExpiration;
-
- Set (key, value, policy, regionName);
- }
-
- IEnumerator IEnumerable.GetEnumerator ()
- {
- // As weird as it is, this method doesn't call the instance GetEnumerator ()
- // - tests show it returns a Hashtable enumerator for some reason.
- var dict = new Hashtable ();
-
- CopyEntries (dict);
- return dict.GetEnumerator ();
- }
-
- void CopyEntries (IDictionary dict)
- {
- foreach (MemoryCacheContainer container in containers) {
- if (container == null)
- continue;
-
- container.CopyEntries (dict);
- }
- }
-
- public long Trim (int percent)
- {
- long ret = 0;
-
- // We should probably sort the containers by their least recently used
- // items, but that is a performance overkill so we'll just resort to a more
- // naive method - each container is trimmed independently of the others.
- foreach (MemoryCacheContainer container in containers) {
- if (container == null)
- continue;
-
- ret += container.Trim (percent);
- }
-
- return ret;
- }
-
- void ValidatePolicy (CacheItemPolicy policy, bool allowUpdateCallback)
- {
- CacheEntryUpdateCallback updateCallback = policy.UpdateCallback;
- if (!allowUpdateCallback && updateCallback != null)
- throw new ArgumentException ("CacheItemPolicy.UpdateCallback must be null.", "policy");
-
- if (updateCallback != null && policy.RemovedCallback != null)
- throw new ArgumentException ("Only one callback can be specified. Either RemovedCallback or UpdateCallback must be null.", "policy");
-
- DateTimeOffset absoluteExpiration = policy.AbsoluteExpiration;
- TimeSpan slidingExpiration = policy.SlidingExpiration;
-
- if (absoluteExpiration != ObjectCache.InfiniteAbsoluteExpiration &&
- slidingExpiration != TimeSpan.Zero)
- throw new ArgumentException (
- "policy",
- "'AbsoluteExpiration' must be ObjectCache.InfiniteAbsoluteExpiration or 'SlidingExpiration' must be TimeSpan.Zero"
- );
-
- long ticks = slidingExpiration.Ticks;
- if (ticks < 0 || ticks > 315360000000000)
- throw new ArgumentOutOfRangeException (
- "policy",
- "SlidingExpiration must be greater than or equal to '00:00:00' and less than or equal to '365.00:00:00'."
- );
-
- CacheItemPriority priority = policy.Priority;
- if (priority < CacheItemPriority.Default || priority > CacheItemPriority.NotRemovable)
- throw new ArgumentOutOfRangeException (
- "policy",
- "'Priority' must be greater than or equal to 'Default' and less than or equal to 'NotRemovable'"
- );
- }
- }
-}
+++ /dev/null
-//
-// MemoryCacheContainer.cs
-//
-// Authors:
-// Marek Habersack <mhabersack@novell.com>
-//
-// Copyright (C) 2010 Novell, Inc. (http://novell.com/)
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-using System;
-using System.Collections;
-using System.Collections.Generic;
-using System.Collections.Specialized;
-using System.Configuration;
-using System.Diagnostics;
-using System.Reflection;
-using System.Runtime.Caching.Configuration;
-using System.Threading;
-
-namespace System.Runtime.Caching
-{
- sealed class MemoryCacheContainer : IDisposable
- {
- const int DEFAULT_LRU_LOWER_BOUND = 10;
-
- ReaderWriterLockSlim cache_lock = new ReaderWriterLockSlim ();
-
- SortedDictionary <string, MemoryCacheEntry> cache;
- MemoryCache owner;
- MemoryCachePerformanceCounters perfCounters;
- MemoryCacheEntryPriorityQueue timedItems;
- MemoryCacheLRU lru;
- Timer expirationTimer;
-
- public int ID {
- get; private set;
- }
-
- public long Count {
- get { return (long)cache.Count; }
- }
-
- public MemoryCacheContainer (MemoryCache owner, int id, MemoryCachePerformanceCounters perfCounters)
- {
- if (owner == null)
- throw new ArgumentNullException ("owner");
-
- this.owner = owner;
- this.ID = id;
- this.perfCounters = perfCounters;
- cache = new SortedDictionary <string, MemoryCacheEntry> ();
- lru = new MemoryCacheLRU (this, DEFAULT_LRU_LOWER_BOUND);
- }
-
- bool ExpireIfNeeded (string key, MemoryCacheEntry entry, bool needsLock = true, CacheEntryRemovedReason reason = CacheEntryRemovedReason.Expired)
- {
- bool locked = false;
-
- try {
- if (entry.IsExpired) {
- if (needsLock) {
- cache_lock.EnterWriteLock ();
- locked = true;
- }
-
- cache.Remove (key);
- perfCounters.Decrement (MemoryCachePerformanceCounters.CACHE_ENTRIES);
- entry.Removed (owner, CacheEntryRemovedReason.Expired);
-
- return true;
- }
- } finally {
- if (locked)
- cache_lock.ExitWriteLock ();
- }
-
- return false;
- }
-
- public void Dispose ()
- {
- if (expirationTimer != null) {
- expirationTimer.Dispose ();
- expirationTimer = null;
- }
- }
-
- public void CopyEntries (IDictionary dict)
- {
- bool locked = false;
- try {
- cache_lock.EnterWriteLock ();
- locked = true;
-
- MemoryCacheEntry entry;
- foreach (var de in cache) {
- entry = de.Value;
-
- if (entry.IsExpired)
- continue;
-
- dict.Add (de.Key, entry.Value);
- }
- } finally {
- if (locked)
- cache_lock.ExitWriteLock ();
- }
- }
-
- public bool ContainsKey (string key)
- {
- bool readLocked = false;
- try {
- cache_lock.EnterUpgradeableReadLock ();
- readLocked = true;
-
- MemoryCacheEntry entry;
- if (cache.TryGetValue (key, out entry)) {
- if (ExpireIfNeeded (key, entry))
- return false;
-
- return true;
- }
-
- return false;
- } finally {
- if (readLocked)
- cache_lock.ExitUpgradeableReadLock ();
- }
- }
-
- // NOTE: this method _MUST_ be called with the write lock held
- void AddToCache (string key, MemoryCacheEntry entry, bool update = false)
- {
- if (update)
- cache [key] = entry;
- else
- cache.Add (key, entry);
- lru.Update (entry);
- entry.Added ();
- if (!update)
- perfCounters.Increment (MemoryCachePerformanceCounters.CACHE_ENTRIES);
-
- if (entry.IsExpirable)
- UpdateExpirable (entry);
- }
-
- // NOTE: this method _MUST_ be called with the write lock held
- void UpdateExpirable (MemoryCacheEntry entry)
- {
- if (timedItems == null)
- timedItems = new MemoryCacheEntryPriorityQueue ();
-
- timedItems.Enqueue (entry);
-
- if (expirationTimer == null)
- expirationTimer = new Timer (RemoveExpiredItems, null, owner.TimerPeriod, owner.TimerPeriod);
- }
-
- void RemoveExpiredItems (object state)
- {
- DoRemoveExpiredItems (true);
- }
-
- long DoRemoveExpiredItems (bool needLock)
- {
- long count = 0;
- bool locked = false;
- try {
- if (needLock) {
- cache_lock.EnterWriteLock ();
- locked = true;
- }
-
- if (timedItems == null)
- return 0;
-
- long now = DateTime.UtcNow.Ticks;
- MemoryCacheEntry entry = timedItems.Peek ();
-
- while (entry != null) {
- if (entry.Disabled) {
- timedItems.Dequeue ();
- entry = timedItems.Peek ();
- continue;
- }
-
- if (entry.ExpiresAt > now)
- break;
-
- timedItems.Dequeue ();
-
- if (entry.IsSliding && entry.ExpiresAtNext > now) {
- entry.ResetSlidingExpiry ();
- timedItems.Enqueue (entry);
- break;
- }
-
- count++;
- DoRemoveEntry (entry, true, entry.Key, CacheEntryRemovedReason.Expired);
- entry = timedItems.Peek ();
- }
-
- if (entry == null) {
- timedItems = null;
- expirationTimer.Dispose ();
- expirationTimer = null;
- }
-
- return count;
- } finally {
- if (locked)
- cache_lock.ExitWriteLock ();
- }
- }
-
- public object AddOrGetExisting (string key, object value, CacheItemPolicy policy)
- {
- bool readLocked = false, writeLocked = false;
- try {
- cache_lock.EnterUpgradeableReadLock ();
- readLocked = true;
-
- MemoryCacheEntry entry;
- if (cache.TryGetValue (key, out entry) && entry != null) {
- perfCounters.Increment (MemoryCachePerformanceCounters.CACHE_HITS);
- if (entry.IsSliding)
- entry.UpdateSlidingExpiry ();
-
- return entry.Value;
- }
- perfCounters.Increment (MemoryCachePerformanceCounters.CACHE_MISSES);
-
- cache_lock.EnterWriteLock ();
- writeLocked = true;
-
- if (policy == null)
- entry = new MemoryCacheEntry (owner, key, value);
- else
- entry = new MemoryCacheEntry (owner, key, value,
- policy.AbsoluteExpiration,
- policy.ChangeMonitors,
- policy.Priority,
- policy.RemovedCallback,
- policy.SlidingExpiration,
- policy.UpdateCallback);
-
- AddToCache (key, entry);
- return null;
- } finally {
- if (writeLocked)
- cache_lock.ExitWriteLock ();
- if (readLocked)
- cache_lock.ExitUpgradeableReadLock ();
- }
- }
-
- public MemoryCacheEntry GetEntry (string key)
- {
- bool readLocked = false;
- try {
- cache_lock.EnterUpgradeableReadLock ();
- readLocked = true;
-
- MemoryCacheEntry entry;
- if (cache.TryGetValue (key, out entry)) {
- if (entry.IsSliding)
- entry.UpdateSlidingExpiry ();
-
- if (ExpireIfNeeded (key, entry))
- return null;
-
- return entry;
- }
-
- return null;
- } finally {
- if (readLocked)
- cache_lock.ExitUpgradeableReadLock ();
- }
- }
-
- public object Get (string key)
- {
- bool readLocked = false;
- try {
- cache_lock.EnterUpgradeableReadLock ();
- readLocked = true;
-
- MemoryCacheEntry entry;
- if (cache.TryGetValue (key, out entry)) {
- if (entry.IsSliding)
- entry.UpdateSlidingExpiry ();
-
- if (ExpireIfNeeded (key, entry))
- return null;
-
- perfCounters.Increment (MemoryCachePerformanceCounters.CACHE_HITS);
- return entry.Value;
- }
-
- perfCounters.Increment (MemoryCachePerformanceCounters.CACHE_MISSES);
- return null;
- } finally {
- if (readLocked)
- cache_lock.ExitUpgradeableReadLock ();
- }
- }
-
- public object Remove (string key, bool needLock = true, bool updateLRU = true)
- {
- bool writeLocked = false, readLocked = false;
- try {
- if (needLock) {
- cache_lock.EnterUpgradeableReadLock ();
- readLocked = true;
- }
-
- MemoryCacheEntry entry;
- if (!cache.TryGetValue (key, out entry))
- return null;
-
- if (needLock) {
- cache_lock.EnterWriteLock ();
- writeLocked = true;
- }
-
- object ret = entry.Value;
- DoRemoveEntry (entry, updateLRU, key);
- return ret;
- } finally {
- if (writeLocked)
- cache_lock.ExitWriteLock ();
- if (readLocked)
- cache_lock.ExitUpgradeableReadLock ();
- }
- }
-
- // NOTE: this must be called with the write lock held
- void DoRemoveEntry (MemoryCacheEntry entry, bool updateLRU = true, string key = null, CacheEntryRemovedReason reason = CacheEntryRemovedReason.Removed)
- {
- if (key == null)
- key = entry.Key;
-
- cache.Remove (key);
- if (updateLRU)
- lru.Remove (entry);
- perfCounters.Decrement (MemoryCachePerformanceCounters.CACHE_ENTRIES);
- entry.Removed (owner, reason);
- }
-
- public void Set (string key, object value, CacheItemPolicy policy)
- {
- bool locked = false;
- try {
- cache_lock.EnterWriteLock ();
- locked = true;
-
- MemoryCacheEntry mce;
- bool update = false;
- if (cache.TryGetValue (key, out mce)) {
- if (mce != null) {
- perfCounters.Increment (MemoryCachePerformanceCounters.CACHE_HITS);
- mce.Value = value;
- mce.SetPolicy (policy);
- if (mce.IsExpirable)
- UpdateExpirable (mce);
- lru.Update (mce);
- return;
- }
-
- update = true;
- }
- perfCounters.Increment (MemoryCachePerformanceCounters.CACHE_MISSES);
- if (policy != null)
- mce = new MemoryCacheEntry (owner, key, value,
- policy.AbsoluteExpiration,
- policy.ChangeMonitors,
- policy.Priority,
- policy.RemovedCallback,
- policy.SlidingExpiration,
- policy.UpdateCallback);
- else
- mce = new MemoryCacheEntry (owner, key, value);
- AddToCache (key, mce, update);
- } finally {
- if (locked)
- cache_lock.ExitWriteLock ();
- }
- }
-
- public long Trim (int percent)
- {
- int count = cache.Count;
- if (count == 0)
- return 0;
-
- long goal = (long)((count * percent) / 100);
- bool locked = false;
- long ret = 0;
-
- try {
- cache_lock.EnterWriteLock ();
- locked = true;
- ret = DoRemoveExpiredItems (false);
-
- goal -= ret;
- if (goal > 0)
- ret += lru.Trim (goal);
- } finally {
- if (locked)
- cache_lock.ExitWriteLock ();
- }
-
- return ret;
- }
- }
-}
+++ /dev/null
-//
-// MemoryCacheEntry.cs
-//
-// Authors:
-// Marek Habersack <mhabersack@novell.com>
-//
-// Copyright (C) 2010 Novell, Inc. (http://novell.com/)
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-using System;
-using System.Collections.Generic;
-using System.Collections.ObjectModel;
-using System.Reflection;
-using System.Runtime.InteropServices;
-
-namespace System.Runtime.Caching
-{
- sealed class MemoryCacheEntry
- {
- object value;
- DateTimeOffset absoluteExpiration;
- Collection <ChangeMonitor> monitors;
- CacheItemPriority priority;
- CacheEntryRemovedCallback removedCallback;
- TimeSpan slidingExpiration;
- CacheEntryUpdateCallback updateCallback;
- MemoryCache owner;
- long expiresAt;
- long expiresAtNext;
- bool disabled;
-
- public bool Disabled {
- get { return disabled; }
- set {
- if (value) {
- this.value = null;
- this.Key = null;
- this.disabled = true;
- } else
- this.disabled = false;
- }
- }
-
- public bool IsExpired {
- get {
- if (absoluteExpiration != ObjectCache.InfiniteAbsoluteExpiration && absoluteExpiration.UtcTicks < DateTime.UtcNow.Ticks)
- return true;
-
- if (IsSliding && expiresAtNext > 0 && DateTime.UtcNow.Ticks > expiresAtNext)
- return true;
-
- return false;
- }
- }
-
- public bool IsRemovable {
- get { return priority != CacheItemPriority.NotRemovable; }
- }
-
- public bool IsExpirable {
- get { return expiresAt > 0; }
- }
-
- public bool IsSliding {
- get { return slidingExpiration != ObjectCache.NoSlidingExpiration; }
- }
-
- public string Key {
- get; private set;
- }
-
- public DateTime LastModified {
- get; private set;
- }
-
- public long ExpiresAt {
- get { return expiresAt; }
- }
-
- public long ExpiresAtNext {
- get { return expiresAtNext; }
- }
-
- public void UpdateSlidingExpiry () {
- if (IsSliding) {
- expiresAtNext = GetSlidingExpiry ();
- }
- }
-
- public void ResetSlidingExpiry () {
- if (IsSliding) {
- expiresAt = GetSlidingExpiry ();
- expiresAtNext = expiresAt;
- }
- }
-
- public object Value {
- get { return value; }
- set {
- this.value = value;
- LastModified = DateTime.UtcNow;
- }
- }
-
- public MemoryCacheEntry (MemoryCache owner, string key, object value)
- : this (owner, key, value, DateTimeOffset.MaxValue, null, CacheItemPriority.Default, null, TimeSpan.MaxValue, null)
- {
- }
-
- public MemoryCacheEntry (MemoryCache owner, string key, object value, DateTimeOffset absoluteExpiration, Collection <ChangeMonitor> monitors,
- CacheItemPriority priority, CacheEntryRemovedCallback removedCallback, TimeSpan slidingExpiration,
- CacheEntryUpdateCallback updateCallback)
- {
- if (value == null)
- throw new ArgumentNullException ("value");
-
- if (owner == null)
- throw new ArgumentNullException ("owner");
-
- this.owner = owner;
- this.Key = key;
- this.Value = value;
- this.absoluteExpiration = absoluteExpiration;
- this.monitors = monitors;
- this.priority = priority;
- this.removedCallback = removedCallback;
- this.slidingExpiration = slidingExpiration;
- this.updateCallback = updateCallback;
- this.LastModified = DateTime.UtcNow;
-
- if (absoluteExpiration != ObjectCache.InfiniteAbsoluteExpiration)
- expiresAt = absoluteExpiration.UtcTicks;
- else if (slidingExpiration != ObjectCache.NoSlidingExpiration)
- expiresAt = GetSlidingExpiry ();
- else
- expiresAt = 0;
-
- expiresAtNext = expiresAt;
- }
-
- public void Added ()
- {
- Disabled = false;
- if (monitors == null || monitors.Count == 0)
- return;
-
- foreach (ChangeMonitor monitor in monitors)
- monitor.NotifyOnChanged (OnMonitorChanged);
- }
-
- public override int GetHashCode ()
- {
- return Key.GetHashCode ();
- }
-
- void OnMonitorChanged (object state)
- {
- owner.Remove (this);
- }
-
- public void Removed (MemoryCache owner, CacheEntryRemovedReason reason)
- {
- if (removedCallback == null) {
- Disabled = true;
- return;
- }
-
- try {
- removedCallback (new CacheEntryRemovedArguments (owner, reason, new CacheItem (Key, Value)));
- } catch {
- // ignore - we don't care about the exceptions thrown inside the
- // handler
- } finally {
- Disabled = true;
- }
- }
-
- public void Updated (MemoryCache owner, CacheEntryRemovedReason reason)
- {
- if (updateCallback == null)
- return;
-
- try {
- var args = new CacheEntryUpdateArguments (owner, reason, Key, null);
- updateCallback (args);
- } catch {
- // ignore - we don't care about the exceptions thrown inside the
- // handler
- }
- }
-
- public void SetPolicy (CacheItemPolicy policy)
- {
- if (policy == null)
- return;
-
- absoluteExpiration = policy.AbsoluteExpiration;
- monitors = policy.ChangeMonitors;
- priority = policy.Priority;
- removedCallback = policy.RemovedCallback;
- slidingExpiration = policy.SlidingExpiration;
- updateCallback = policy.UpdateCallback;
- }
-
- private long GetSlidingExpiry()
- {
- return DateTime.UtcNow.Ticks + slidingExpiration.Ticks;
- }
- }
-}
+++ /dev/null
-//
-// MemoryCacheEntryChangeMonitor.cs
-//
-// Authors:
-// Marek Habersack <mhabersack@novell.com>
-//
-// Copyright (C) 2010 Novell, Inc. (http://novell.com/)
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-using System;
-using System.Collections;
-using System.Collections.Generic;
-using System.Collections.ObjectModel;
-using System.Text;
-
-namespace System.Runtime.Caching
-{
- sealed class MemoryCacheEntryChangeMonitor : CacheEntryChangeMonitor
- {
- ReadOnlyCollection <string> cacheKeys;
- DateTimeOffset lastModified;
-// MemoryCache owner;
- string uniqueId;
-
- public override ReadOnlyCollection <string> CacheKeys {
- get { return cacheKeys; }
- }
-
- public override DateTimeOffset LastModified {
- get { return lastModified; }
- }
-
- public override string RegionName {
- get { return null; }
- }
-
- public override string UniqueId {
- get { return uniqueId; }
- }
-
- 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
- }
-
- protected override void Dispose (bool disposing)
- {
- }
- }
-}
+++ /dev/null
-//
-// Author(s):
-// Marek Habersack <mhabersack@novell.com>
-//
-// (C) 2009-2010 Novell, Inc (http://novell.com)
-//
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Text;
-using System.Threading;
-
-namespace System.Runtime.Caching
-{
- sealed partial class MemoryCacheEntryPriorityQueue
- {
- const int INITIAL_HEAP_SIZE = 32;
- const int HEAP_RESIZE_THRESHOLD = 8192;
-
- MemoryCacheEntry[] heap;
- int heapSize = 0;
- int heapCount = 0;
- ReaderWriterLockSlim queueLock;
-
- public int Count {
- get { return heapCount; }
- }
-
- public int Size {
- get { return heapSize; }
- }
-
- public MemoryCacheEntryPriorityQueue ()
- {
- queueLock = new ReaderWriterLockSlim ();
- }
-
- MemoryCacheEntry[] GetHeapWithGrow ()
- {
- if (heap == null) {
- heap = new MemoryCacheEntry [INITIAL_HEAP_SIZE];
- heapSize = INITIAL_HEAP_SIZE;
- heapCount = 0;
- return heap;
- }
-
- if (heapCount >= heapSize) {
- checked {
- heapSize <<= 1;
- }
-
- if (heapSize <= Int32.MaxValue)
- Array.Resize <MemoryCacheEntry> (ref heap, heapSize);
- }
-
- return heap;
- }
-
- MemoryCacheEntry[] GetHeapWithShrink ()
- {
- if (heap == null)
- return null;
-
- if (heapSize > HEAP_RESIZE_THRESHOLD) {
- int halfTheSize, newSize;
- checked {
- halfTheSize = heapSize >> 1;
- newSize = halfTheSize + (heapCount / 3);
- }
-
- if ((heapCount < halfTheSize) && newSize > -1) {
- Array.Resize <MemoryCacheEntry> (ref heap, newSize);
- heapSize = newSize;
- }
- }
-
- return heap;
- }
-
- public void Enqueue (MemoryCacheEntry item)
- {
- if (item == null)
- return;
-
- bool locked = false;
- MemoryCacheEntry[] heap;
-
- try {
- queueLock.EnterWriteLock ();
- locked = true;
- heap = GetHeapWithGrow ();
- heap [checked(heapCount++)] = item;
- BubbleUp (heap);
- } finally {
- if (locked)
- queueLock.ExitWriteLock ();
- }
- }
-
- public MemoryCacheEntry Dequeue ()
- {
- MemoryCacheEntry ret = null;
- MemoryCacheEntry[] heap;
- bool locked = false;
- int index;
-
- try {
- queueLock.EnterWriteLock ();
- locked = true;
- heap = GetHeapWithShrink ();
- if (heap == null || heapCount == 0)
- return null;
-
- ret = heap [0];
- index = checked(--heapCount);
- heap [0] = heap [index];
- heap [index] = null;
-
- if (heapCount > 0)
- BubbleDown (heap);
-
- return ret;
- } finally {
- if (locked)
- queueLock.ExitWriteLock ();
- }
- }
-
- public MemoryCacheEntry Peek ()
- {
- bool locked = false;
-
- try {
- queueLock.EnterReadLock ();
- locked = true;
- if (heap == null || heapCount == 0)
- return null;
-
- return heap [0];
- } finally {
- if (locked)
- queueLock.ExitReadLock ();
- }
- }
-
- void BubbleDown (MemoryCacheEntry[] heap)
- {
- int index = 0;
- int left = 1;
- int right = 2;
- MemoryCacheEntry item = heap [0];
- int selected = (right < heapCount && heap [right].ExpiresAt < heap [left].ExpiresAt) ? 2 : 1;
-
- while (selected < heapCount && heap [selected].ExpiresAt < item.ExpiresAt) {
- heap [index] = heap [selected];
- index = selected;
- left = checked((index << 1) + 1);
- right = left + 1;
- selected = right < heapCount && heap [right].ExpiresAt < heap [left].ExpiresAt ? right : left;
- }
- heap [index] = item;
- }
-
- void BubbleUp (MemoryCacheEntry[] heap)
- {
- int index, parentIndex;
- MemoryCacheEntry parent, item;
-
- if (heapCount <= 1)
- return;
-
- index = checked(heapCount - 1);
- parentIndex = checked((index - 1) >> 1);
-
- item = heap [index];
- while (index > 0) {
- parent = heap [parentIndex];
- if (heap [index].ExpiresAt >= parent.ExpiresAt)
- break;
-
- heap [index] = parent;
- heap [parentIndex] = item;
-
- index = parentIndex;
- parentIndex = (index - 1) >> 1;
- }
- }
- }
-}
+++ /dev/null
-//
-// MemoryCacheLRU.cs
-//
-// Authors:
-// Marek Habersack <mhabersack@novell.com>
-//
-// Copyright (C) 2010 Novell, Inc. (http://novell.com/)
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-using System;
-using System.Collections.Generic;
-
-namespace System.Runtime.Caching
-{
- // NOTE: all the public methods in this assume that the owner's write lock is held
- sealed class MemoryCacheLRU
- {
-// int trimLowerBound;
- Dictionary <int, LinkedListNode <MemoryCacheEntry>> index;
- LinkedList <MemoryCacheEntry> lru;
- MemoryCacheContainer owner;
-
- public MemoryCacheLRU (MemoryCacheContainer owner, int trimLowerBound)
- {
-// this.trimLowerBound = trimLowerBound;
- index = new Dictionary <int, LinkedListNode <MemoryCacheEntry>> ();
- lru = new LinkedList <MemoryCacheEntry> ();
- this.owner = owner;
- }
-
- public void Update (MemoryCacheEntry entry)
- {
- if (entry == null)
- return;
-
- int hash = entry.GetHashCode ();
- LinkedListNode <MemoryCacheEntry> node;
-
- if (!index.TryGetValue (hash, out node)) {
- node = new LinkedListNode <MemoryCacheEntry> (entry);
- index.Add (hash, node);
- } else {
- lru.Remove (node);
- node.Value = entry;
- }
-
- lru.AddLast (node);
- }
-
- public void Remove (MemoryCacheEntry entry)
- {
- if (entry == null)
- return;
-
- int hash = entry.GetHashCode ();
- LinkedListNode <MemoryCacheEntry> node;
-
- if (index.TryGetValue (hash, out node)) {
- lru.Remove (node);
- index.Remove (hash);
- }
- }
-
- public long Trim (long upTo)
- {
- int count = index.Count;
- if (count <= 10)
- return 0;
-
- // The list is used below to reproduce .NET's behavior which selects the
- // entries using the LRU order, but it removes them from the cache in the
- // MRU order
- var toremove = new List <MemoryCacheEntry> ((int)upTo);
- long removed = 0;
- MemoryCacheEntry entry;
-
- while (upTo > removed && count > 10) {
- entry = lru.First.Value;
- toremove.Insert (0, entry);
- Remove (entry);
- removed++;
- count--;
- }
-
- foreach (MemoryCacheEntry e in toremove)
- owner.Remove (e.Key, false);
-
- return removed;
- }
- }
-}
+++ /dev/null
-//
-// MemoryCache.cs
-//
-// Authors:
-// Marek Habersack <mhabersack@novell.com>
-//
-// Copyright (C) 2010 Novell, Inc. (http://novell.com/)
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-using System;
-using System.Collections;
-using System.Collections.Generic;
-using System.Diagnostics;
-
-//
-// Counters in the ".NET Memory Cache 4.0" are not documented on MSDN. They were discovered using
-// perfmon there their definition may change without any notice
-//
-namespace System.Runtime.Caching
-{
- sealed class MemoryCachePerformanceCounters : IDisposable
- {
- const string dotNetCategoryName = ".NET Memory Cache 4.0";
-
- public const int CACHE_ENTRIES = 0;
- public const int CACHE_HIT_RATIO = 1;
- public const int CACHE_HITS = 2;
- public const int CACHE_MISSES = 3;
- public const int CACHE_TRIMS = 4;
- public const int CACHE_TURNOVER_RATE = 5;
- const int COUNTERS_LAST = CACHE_TURNOVER_RATE;
-
- PerformanceCounter[] perfCounters;
-
- public MemoryCachePerformanceCounters (string instanceName, bool noCounters)
- {
- var collection = new CounterCreationDataCollection ();
-
- if (!noCounters) {
- if (!PerformanceCounterCategory.Exists (dotNetCategoryName)) {
- // TODO: check:
- //
- // - types of all the counters
- //
- CreateCounter ("Cache Entries", PerformanceCounterType.NumberOfItems64, collection);
- CreateCounter ("Cache Hit Ratio", PerformanceCounterType.RawFraction, collection);
- CreateCounter ("Cache Hits", PerformanceCounterType.NumberOfItems64, collection);
- CreateCounter ("Cache Misses", PerformanceCounterType.NumberOfItems64, collection);
- CreateCounter ("Cache Trims", PerformanceCounterType.NumberOfItems64, collection);
- CreateCounter ("Cache Turnover Rate", PerformanceCounterType.RateOfCountsPerSecond64, collection);
-
- PerformanceCounterCategory.Create (dotNetCategoryName, "System.Runtime.Caching.MemoryCache Performance Counters",
- PerformanceCounterCategoryType.MultiInstance, collection);
- }
-
- perfCounters = new PerformanceCounter [COUNTERS_LAST + 1];
- perfCounters [CACHE_ENTRIES] = new PerformanceCounter (dotNetCategoryName, "Cache Entries", instanceName, false);
- perfCounters [CACHE_ENTRIES].RawValue = 0;
- perfCounters [CACHE_HIT_RATIO] = new PerformanceCounter (dotNetCategoryName, "Cache Hit Ratio", instanceName, false);
- perfCounters [CACHE_HIT_RATIO].RawValue = 0;
- perfCounters [CACHE_HITS] = new PerformanceCounter (dotNetCategoryName, "Cache Hits", instanceName, false);
- perfCounters [CACHE_HITS].RawValue = 0;
- perfCounters [CACHE_MISSES] = new PerformanceCounter (dotNetCategoryName, "Cache Misses", instanceName, false);
- perfCounters [CACHE_MISSES].RawValue = 0;
- perfCounters [CACHE_TRIMS] = new PerformanceCounter (dotNetCategoryName, "Cache Trims", instanceName, false);
- perfCounters [CACHE_TRIMS].RawValue = 0;
- perfCounters [CACHE_TURNOVER_RATE] = new PerformanceCounter (dotNetCategoryName, "Cache Turnover Rate", instanceName, false);
- perfCounters [CACHE_TURNOVER_RATE].RawValue = 0;
- }
- }
-
- public void Dispose ()
- {
- foreach (PerformanceCounter counter in perfCounters) {
- if (counter == null)
- continue;
-
- counter.Dispose ();
- }
- }
-
- public void Decrement (int counteridx)
- {
- if (perfCounters == null || counteridx < 0 || counteridx > COUNTERS_LAST)
- return;
-
- perfCounters [counteridx].Decrement ();
- }
-
- public void Increment (int counteridx)
- {
- if (perfCounters == null || counteridx < 0 || counteridx > COUNTERS_LAST)
- return;
-
- perfCounters [counteridx].Increment ();
- }
-
- void CreateCounter (string name, PerformanceCounterType type, CounterCreationDataCollection collection)
- {
- var ccd = new CounterCreationData ();
-
- ccd.CounterName = name;
- ccd.CounterType = type;
- collection.Add (ccd);
- }
- }
-}
+++ /dev/null
-//
-// ObjectCache.cs
-//
-// Authors:
-// Marek Habersack <mhabersack@novell.com>
-//
-// Copyright (C) 2010 Novell, Inc. (http://novell.com/)
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-using System;
-using System.Collections;
-using System.Collections.Generic;
-using System.Linq;
-using System.Reflection;
-using System.Runtime;
-
-namespace System.Runtime.Caching
-{
- public abstract class ObjectCache : IEnumerable<KeyValuePair<string, object>>, IEnumerable
- {
- static IServiceProvider host;
-
- public static readonly DateTimeOffset InfiniteAbsoluteExpiration = DateTimeOffset.MaxValue;
- public static readonly TimeSpan NoSlidingExpiration = TimeSpan.Zero;
-
- public static IServiceProvider Host {
- get { return host; }
- set {
- if (value == null)
- throw new ArgumentNullException ("value");
-
- if (host != null)
- throw new InvalidOperationException ("The property has already been set, and can only be set once.");
-
- host = value;
- }
- }
-
- public abstract DefaultCacheCapabilities DefaultCacheCapabilities { get; }
- public abstract object this [string key] { get; set; }
- public abstract string Name { get; }
-
- protected ObjectCache ()
- {
- }
-
- public virtual bool Add (CacheItem item, CacheItemPolicy policy)
- {
- return AddOrGetExisting (item, policy) == null;
- }
-
- public virtual bool Add (string key, object value, CacheItemPolicy policy, string regionName = null)
- {
- return AddOrGetExisting (key, value, policy, regionName) == null;
- }
-
- public virtual bool Add (string key, object value, DateTimeOffset absoluteExpiration, string regionName = null)
- {
- return AddOrGetExisting (key, value, absoluteExpiration, regionName) == null;
- }
-
- public abstract CacheItem AddOrGetExisting (CacheItem value, CacheItemPolicy policy);
- public abstract object AddOrGetExisting (string key, object value, CacheItemPolicy policy, string regionName = null);
- public abstract object AddOrGetExisting (string key, object value, DateTimeOffset absoluteExpiration, string regionName = null);
- public abstract bool Contains (string key, string regionName = null);
- public abstract CacheEntryChangeMonitor CreateCacheEntryChangeMonitor (IEnumerable <string> keys, string regionName = null);
- public abstract object Get (string key, string regionName = null);
- public abstract CacheItem GetCacheItem (string key, string regionName = null);
- public abstract long GetCount (string regionName = null);
- protected abstract IEnumerator <KeyValuePair <string, object>> GetEnumerator ();
- public abstract IDictionary <string, object> GetValues (IEnumerable <string> keys, string regionName = null);
-
- public virtual IDictionary <string, object> GetValues (string regionName = null, params string[] keys)
- {
- return GetValues (keys.AsEnumerable <string> (), regionName);
- }
-
- public abstract object Remove (string key, string regionName = null);
- public abstract void Set (CacheItem item, CacheItemPolicy policy);
- public abstract void Set (string key, object value, CacheItemPolicy policy, string regionName = null);
- public abstract void Set (string key, object value, DateTimeOffset absoluteExpiration, string regionName = null);
-
- IEnumerator <KeyValuePair <string,object>> IEnumerable<KeyValuePair<string, object>>.GetEnumerator ()
- {
- return GetEnumerator ();
- }
-
- IEnumerator IEnumerable.GetEnumerator ()
- {
- return GetEnumerator ();
- }
- }
-}
+++ /dev/null
-//
-// OnChangedCallback.cs
-//
-// Authors:
-// Marek Habersack <mhabersack@novell.com>
-//
-// Copyright (C) 2010 Novell, Inc. (http://novell.com/)
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-using System;
-
-namespace System.Runtime.Caching
-{
- public delegate void OnChangedCallback (object state);
-}
+++ /dev/null
-//
-// SqlChangeMonitor.cs
-//
-// Authors:
-// Marek Habersack <mhabersack@novell.com>
-//
-// Copyright (C) 2010 Novell, Inc. (http://novell.com/)
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-using System;
-using System.Data.SqlClient;
-
-namespace System.Runtime.Caching
-{
- public sealed class SqlChangeMonitor : ChangeMonitor
- {
- const string uniqueId = null;
-
- public override string UniqueId {
- get { return uniqueId; }
- }
-
- public SqlChangeMonitor (SqlDependency dependency)
- {
- if (dependency == null)
- throw new ArgumentNullException ("dependency");
-
- throw new NotImplementedException ();
- }
-
- protected override void Dispose (bool disposing)
- {
- throw new NotImplementedException ();
- }
- }
-}