Imported Upstream version 4.0.0~alpha1

Former-commit-id: 806294f5ded97629b74c85c09952f2a74fe182d9
This commit is contained in:
Jo Shields
2015-04-07 09:35:12 +01:00
parent 283343f570
commit 3c1f479b9d
22469 changed files with 2931443 additions and 869343 deletions

View File

@@ -0,0 +1,83 @@
//
// CacheEntryCollection.cs
//
// Authors:
// Marcos Henrih (marcos.henrich@xamarin.com)
//
// Copyright 2014 Xamarin, Inc (http://www.xamarin.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.Collections;
using System.Collections.Generic;
using System.Timers;
namespace System.Runtime.Caching
{
interface ICacheEntryHelper : IComparer<MemoryCacheEntry>
{
DateTime GetDateTime (MemoryCacheEntry entry);
}
class CacheEntryCollection
{
protected MemoryCacheStore store;
private ICacheEntryHelper helper;
private SortedSet <MemoryCacheEntry> entries;
protected CacheEntryCollection (MemoryCacheStore store, ICacheEntryHelper helper)
{
this.store = store;
this.helper = helper;
entries = new SortedSet <MemoryCacheEntry> (helper);
}
protected void Add (MemoryCacheEntry entry)
{
entries.Add (entry);
}
protected void Remove (MemoryCacheEntry entry)
{
entries.Remove (entry);
}
protected int FlushItems (DateTime limit, CacheEntryRemovedReason reason, bool blockInsert, int count = int.MaxValue)
{
var flushedItems = 0;
if (blockInsert)
store.BlockInsert ();
foreach (var entry in entries) {
if (helper.GetDateTime (entry) > limit || flushedItems >= count)
break;
flushedItems++;
}
for (var f = 0; f < flushedItems; f++)
store.Remove (entries.Min, null, reason);
if (blockInsert)
store.UnblockInsert ();
return flushedItems;
}
}
}

View File

@@ -0,0 +1,81 @@
// This file implements the classes ExpiresEntryRef and CacheExpires missing from .NET reference source
using System.Threading;
namespace System.Runtime.Caching
{
class ExpiresEntryRef
{
public static ExpiresEntryRef INVALID = new ExpiresEntryRef ();
public bool IsInvalid {
get { return this == INVALID; }
}
}
class CacheExpiresHelper : ICacheEntryHelper
{
public int Compare(MemoryCacheEntry entry1, MemoryCacheEntry entry2)
{
return DateTime.Compare (entry1.UtcAbsExp , entry2.UtcAbsExp);
}
public DateTime GetDateTime (MemoryCacheEntry entry)
{
return entry.UtcAbsExp;
}
}
class CacheExpires : CacheEntryCollection
{
public static TimeSpan MIN_UPDATE_DELTA = new TimeSpan (0, 0, 1);
public static TimeSpan EXPIRATIONS_INTERVAL = new TimeSpan (0, 0, 20);
public static CacheExpiresHelper helper = new CacheExpiresHelper ();
Timer timer;
public CacheExpires (MemoryCacheStore store)
: base (store, helper)
{
}
public void Add (MemoryCacheEntry entry)
{
entry.ExpiresEntryRef = new ExpiresEntryRef ();
base.Add (entry);
}
public void Remove (MemoryCacheEntry entry)
{
base.Remove (entry);
entry.ExpiresEntryRef = ExpiresEntryRef.INVALID;
}
public void UtcUpdate (MemoryCacheEntry entry, DateTime utcAbsExp)
{
base.Remove (entry);
entry.UtcAbsExp = utcAbsExp;
base.Add (entry);
}
public void EnableExpirationTimer (bool enable)
{
if (enable) {
if (timer != null)
return;
var period = (int) EXPIRATIONS_INTERVAL.TotalMilliseconds;
timer = new Timer ((o) => FlushExpiredItems (true), null, period, period);
} else {
timer.Dispose ();
timer = null;
}
}
public int FlushExpiredItems (bool blockInsert)
{
return base.FlushItems (DateTime.UtcNow, CacheEntryRemovedReason.Expired, blockInsert);
}
}
}

View File

@@ -0,0 +1,82 @@
// This file implements the classes UsageEntryRef and CacheUsage missing from .NET reference source
namespace System.Runtime.Caching {
class UsageEntryRef {
public static UsageEntryRef INVALID = new UsageEntryRef ();
public bool IsInvalid {
get { return this == INVALID; }
}
// This is used to compare MemoryCacheEntry that have the same UtcLastUpdateUsage.
public int DateTimeIndex {
get; set;
}
}
class CacheUsageHelper : ICacheEntryHelper
{
public int Compare(MemoryCacheEntry entry1, MemoryCacheEntry entry2)
{
var ret = DateTime.Compare (entry1.UtcLastUpdateUsage , entry2.UtcLastUpdateUsage);
if (ret == 0)
return entry1.UsageEntryRef.DateTimeIndex - entry2.UsageEntryRef.DateTimeIndex;
return ret;
}
public DateTime GetDateTime (MemoryCacheEntry entry)
{
return entry.UtcLastUpdateUsage;
}
}
class CacheUsage : CacheEntryCollection {
public static TimeSpan CORRELATED_REQUEST_TIMEOUT = new TimeSpan (0, 0, 10);
public static TimeSpan MIN_LIFETIME_FOR_USAGE = new TimeSpan (0, 0, 10);
public static CacheUsageHelper helper = new CacheUsageHelper ();
public DateTime prevDateTime;
public int dateTimeIndex;
public CacheUsage (MemoryCacheStore store)
: base (store, helper)
{
}
public void Add (MemoryCacheEntry entry)
{
var now = DateTime.UtcNow;
if (now == prevDateTime)
dateTimeIndex++;
else
dateTimeIndex = 0;
prevDateTime = now;
entry.UtcLastUpdateUsage = now;
entry.UsageEntryRef = new UsageEntryRef ();
entry.UsageEntryRef.DateTimeIndex = dateTimeIndex;
base.Add (entry);
}
public void Remove (MemoryCacheEntry entry)
{
base.Remove (entry);
entry.UsageEntryRef = UsageEntryRef.INVALID;
}
public void Update (MemoryCacheEntry entry)
{
base.Remove (entry);
entry.UtcLastUpdateUsage = DateTime.UtcNow;
base.Add (entry);
}
public int FlushUnderUsedItems (int count)
{
return base.FlushItems (DateTime.MaxValue, CacheEntryRemovedReason.Evicted, true, count);
}
}
}

View File

@@ -0,0 +1,238 @@
// This is a copy of external/referencesource/System.Runtime.Caching/Resources/R.Designer.cs
// This verison does not use ResourceManager, instead it uses hard coded strings.
// This should be removed once Mono has access to .NET resources.
namespace System.Runtime.Caching.Resources {
using System;
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// This class was auto-generated by the StronglyTypedResourceBuilder
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class R {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification = "Grandfathered suppression from original caching code checkin")]
internal R() {
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("System.Runtime.Caching.Resources.R", typeof(R).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
/// <summary>
/// Looks up a localized string similar to &apos;{0}&apos; must be greater than or equal to &apos;{1}&apos; and less than or equal to &apos;{2}&apos;..
/// </summary>
internal static string Argument_out_of_range {
get {
return "Argument_out_of_range";
}
}
/// <summary>
/// Looks up a localized string similar to The collection &apos;{0}&apos; contains a null element..
/// </summary>
internal static string Collection_contains_null_element {
get {
return "Collection_contains_null_element";
}
}
/// <summary>
/// Looks up a localized string similar to The collection &apos;{0}&apos; contains a null or empty string..
/// </summary>
internal static string Collection_contains_null_or_empty_string {
get {
return "Collection_contains_null_or_empty_string";
}
}
/// <summary>
/// Looks up a localized string similar to Unable to retrieve configuration section &apos;{0}&apos;..
/// </summary>
internal static string Config_unable_to_get_section {
get {
return "Config_unable_to_get_section";
}
}
/// <summary>
/// Looks up a localized string similar to Default is a reserved MemoryCache name..
/// </summary>
internal static string Default_is_reserved {
get {
return "Default_is_reserved";
}
}
/// <summary>
/// Looks up a localized string similar to The collection &apos;{0}&apos; is empty..
/// </summary>
internal static string Empty_collection {
get {
return "Empty_collection";
}
}
/// <summary>
/// Looks up a localized string similar to Initialization has not completed yet. The InitializationComplete method must be invoked before Dispose is invoked..
/// </summary>
internal static string Init_not_complete {
get {
return "Init_not_complete";
}
}
/// <summary>
/// Looks up a localized string similar to One of the following parameters must be specified: dependencies, absoluteExpiration, slidingExpiration..
/// </summary>
internal static string Invalid_argument_combination {
get {
return "Invalid_argument_combination";
}
}
/// <summary>
/// Looks up a localized string similar to Only one callback can be specified. Either RemovedCallback or UpdateCallback must be null..
/// </summary>
internal static string Invalid_callback_combination {
get {
return "Invalid_callback_combination";
}
}
/// <summary>
/// Looks up a localized string similar to AbsoluteExpiration must be DateTimeOffset.MaxValue or SlidingExpiration must be TimeSpan.Zero..
/// </summary>
internal static string Invalid_expiration_combination {
get {
return "Invalid_expiration_combination";
}
}
/// <summary>
/// Looks up a localized string similar to Invalid state..
/// </summary>
internal static string Invalid_state {
get {
return "Invalid_state";
}
}
/// <summary>
/// Looks up a localized string similar to The method has already been invoked, and can only be invoked once..
/// </summary>
internal static string Method_already_invoked {
get {
return "Method_already_invoked";
}
}
/// <summary>
/// Looks up a localized string similar to The property has already been set, and can only be set once..
/// </summary>
internal static string Property_already_set {
get {
return "Property_already_set";
}
}
/// <summary>
/// Looks up a localized string similar to Invalid configuration: {0}=&quot;{1}&quot;. The {0} value must be a time interval that can be parsed by System.TimeSpan.Parse..
/// </summary>
internal static string TimeSpan_invalid_format {
get {
return "TimeSpan_invalid_format";
}
}
/// <summary>
/// Looks up a localized string similar to CacheItemUpdateCallback must be null..
/// </summary>
internal static string Update_callback_must_be_null {
get {
return "Update_callback_must_be_null";
}
}
/// <summary>
/// Looks up a localized string similar to Invalid configuration: {0}=&quot;{1}&quot;. The {0} value must be a non-negative 32-bit integer..
/// </summary>
internal static string Value_must_be_non_negative_integer {
get {
return "Value_must_be_non_negative_integer";
}
}
/// <summary>
/// Looks up a localized string similar to Invalid configuration: {0}=&quot;{1}&quot;. The {0} value must be a positive 32-bit integer..
/// </summary>
internal static string Value_must_be_positive_integer {
get {
return "Value_must_be_positive_integer";
}
}
/// <summary>
/// Looks up a localized string similar to Invalid configuration: {0}=&quot;{1}&quot;. The {0} value cannot be greater than &apos;{2}&apos;..
/// </summary>
internal static string Value_too_big {
get {
return "Value_too_big";
}
}
/// <summary>
/// Looks up a localized string similar to An empty string is invalid..
/// </summary>
internal static string Empty_string_invalid {
get {
return "Empty_string_invalid";
}
}
/// <summary>
/// Looks up a localized string similar to The parameter regionName must be null..
/// </summary>
internal static string RegionName_not_supported {
get {
return "RegionName_not_supported";
}
}
}
}

View File

@@ -0,0 +1,28 @@
using System;
using System.Runtime.InteropServices;
namespace System.Runtime.Caching {
/*
* This class is used to retrieve the size of an object graph.
* Although Mono has not a way of computing this.
* Known problems:
* - CacheMemoryMonitor does not trim the cache when it reaches its memory size limit.
* - IMemoryCacheManager.UpdateCacheSize is called with incorrect size.
*/
internal class SRef {
private Object _sizedRef;
internal SRef (Object target) {
_sizedRef = target;
}
internal long ApproximateSize {
get { return (long) Marshal.SizeOf (_sizedRef.GetType ()); }
}
internal void Dispose() {
}
}
}