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

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,431 @@
//------------------------------------------------------------------------------
// <copyright file="CacheEntry.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
/*
* CacheEntry
*
* Copyright (c) 1998-1999, Microsoft Corporation
*
*/
namespace System.Web.Caching {
using System.Text;
using System.Threading;
using System.Web;
using System.Web.Util;
using System.Collections;
using System.Web.Management;
using System.Web.Hosting;
using System.Globalization;
internal class CacheKey {
protected const byte BitPublic = 0x20;
protected const byte BitOutputCache = 0x40;
protected string _key; /* key to the item */
protected byte _bits; /* cache lifetime state and public property */
int _hashCode;
internal CacheKey(String key, bool isPublic) {
if (key == null) {
throw new ArgumentNullException("key");
}
_key = key;
if (isPublic) {
_bits = BitPublic;
}
else if (key[0] == CacheInternal.PrefixOutputCache[0]) {
_bits |= BitOutputCache;
}
#if DBG
if (!isPublic) {
Debug.Assert(CacheInternal.PrefixFIRST[0] <= key[0] && key[0] <= CacheInternal.PrefixLAST[0],
"CacheInternal.PrefixFIRST[0] <= key[0] && key[0] <= CacheInternal.PrefixLAST[0], key=" + key);
}
#endif
}
internal String Key {
get {return _key;}
}
internal bool IsOutputCache {
get { return (_bits & BitOutputCache) != 0; }
}
internal bool IsPublic {
get { return (_bits & BitPublic) != 0; }
}
public override int GetHashCode() {
if (_hashCode == 0) {
_hashCode = _key.GetHashCode();
}
return _hashCode;
}
#if DBG
public override string ToString() {
return (IsPublic ? "P:" : "I:") + _key;
}
#endif
}
/*
* An entry in the cache.
* Overhead is 68 bytes + object header.
*/
internal sealed class CacheEntry : CacheKey, ICacheDependencyChanged {
static readonly DateTime NoAbsoluteExpiration = DateTime.MaxValue;
static readonly TimeSpan NoSlidingExpiration = TimeSpan.Zero;
const CacheItemPriority CacheItemPriorityMin = CacheItemPriority.Low;
const CacheItemPriority CacheItemPriorityMax = CacheItemPriority.NotRemovable;
static readonly TimeSpan OneYear = new TimeSpan(365, 0, 0, 0);
internal enum EntryState : byte {
NotInCache = 0x00, // Created but not in hashtable
AddingToCache = 0x01, // In hashtable only
AddedToCache = 0x02, // In hashtable + expires + usage
RemovingFromCache = 0x04, // Removed from hashtable only
RemovedFromCache = 0x08, // Removed from hashtable & expires & usage
Closed = 0x10,
}
const byte EntryStateMask = 0x1f;
// protected const byte BitPublic = 0x20;
// item
object _value; /* value */
DateTime _utcCreated; /* creation date */
// expiration
DateTime _utcExpires; /* when this item expires */
TimeSpan _slidingExpiration; /* expiration interval */
byte _expiresBucket; /* index of the expiration list (bucket) */
ExpiresEntryRef _expiresEntryRef; /* ref into the expiration list */
// usage
byte _usageBucket; /* index of the usage list (== priority-1) */
UsageEntryRef _usageEntryRef; /* ref into the usage list */
DateTime _utcLastUpdate; /* time we last updated usage */
// dependencies
CacheDependency _dependency; /* dependencies this item has */
object _onRemovedTargets; /* targets of OnRemove notification */
/*
* ctor.
*/
internal CacheEntry(
String key,
Object value,
CacheDependency dependency,
CacheItemRemovedCallback onRemovedHandler,
DateTime utcAbsoluteExpiration,
TimeSpan slidingExpiration,
CacheItemPriority priority,
bool isPublic) :
base(key, isPublic) {
if (value == null) {
throw new ArgumentNullException("value");
}
if (slidingExpiration < TimeSpan.Zero || OneYear < slidingExpiration) {
throw new ArgumentOutOfRangeException("slidingExpiration");
}
if (utcAbsoluteExpiration != Cache.NoAbsoluteExpiration && slidingExpiration != Cache.NoSlidingExpiration) {
throw new ArgumentException(SR.GetString(SR.Invalid_expiration_combination));
}
if (priority < CacheItemPriorityMin || CacheItemPriorityMax < priority) {
throw new ArgumentOutOfRangeException("priority");
}
_value = value;
_dependency = dependency;
_onRemovedTargets = onRemovedHandler;
_utcCreated = DateTime.UtcNow;
_slidingExpiration = slidingExpiration;
if (_slidingExpiration > TimeSpan.Zero) {
_utcExpires = _utcCreated + _slidingExpiration;
}
else {
_utcExpires = utcAbsoluteExpiration;
}
_expiresEntryRef = ExpiresEntryRef.INVALID;
_expiresBucket = 0xff;
_usageEntryRef = UsageEntryRef.INVALID;
if (priority == CacheItemPriority.NotRemovable) {
_usageBucket = 0xff;
}
else {
_usageBucket = (byte) (priority - 1);
}
}
internal Object Value {
get {return _value;}
}
internal DateTime UtcCreated {
get {return _utcCreated;}
}
internal EntryState State {
get { return (EntryState) (_bits & EntryStateMask); }
set { _bits = (byte) (((uint) _bits & ~(uint)EntryStateMask) | (uint) value); }
}
internal DateTime UtcExpires {
get {return _utcExpires;}
set {_utcExpires = value;}
}
internal TimeSpan SlidingExpiration {
get {return _slidingExpiration;}
}
internal byte ExpiresBucket {
get {return _expiresBucket;}
set {_expiresBucket = value;}
}
internal ExpiresEntryRef ExpiresEntryRef {
get {return _expiresEntryRef;}
set {_expiresEntryRef = value;}
}
internal bool HasExpiration() {
return _utcExpires < DateTime.MaxValue;
}
internal bool InExpires() {
return !_expiresEntryRef.IsInvalid;
}
internal byte UsageBucket {
get {return _usageBucket;}
}
internal UsageEntryRef UsageEntryRef {
get {return _usageEntryRef;}
set {_usageEntryRef = value;}
}
internal DateTime UtcLastUsageUpdate {
get {return _utcLastUpdate;}
set {_utcLastUpdate = value;}
}
internal bool HasUsage() {
return _usageBucket != 0xff;
}
internal bool InUsage() {
return !_usageEntryRef.IsInvalid;
}
internal CacheDependency Dependency {
get {return _dependency;}
}
internal void MonitorDependencyChanges() {
// need to protect against the item being closed
CacheDependency dependency = _dependency;
if (dependency != null && State == EntryState.AddedToCache) {
if (!dependency.Use()) {
throw new InvalidOperationException(
SR.GetString(SR.Cache_dependency_used_more_that_once));
}
dependency.SetCacheDependencyChanged(this);
}
}
/*
* The entry has changed, so remove ourselves from the cache.
*/
void ICacheDependencyChanged.DependencyChanged(Object sender, EventArgs e) {
if (State == EntryState.AddedToCache) {
HttpRuntime.CacheInternal.Remove(this, CacheItemRemovedReason.DependencyChanged);
}
}
/*
* Helper to call the on-remove callback
*/
private void CallCacheItemRemovedCallback(CacheItemRemovedCallback callback, CacheItemRemovedReason reason) {
if (IsPublic) {
try {
// for public need to impersonate if called outside of request context
if (HttpContext.Current == null) {
using (new ApplicationImpersonationContext()) {
callback(_key, _value, reason);
}
}
else {
callback(_key, _value, reason);
}
}
catch (Exception e) {
// for public need to report application error
HttpApplicationFactory.RaiseError(e);
try {
WebBaseEvent.RaiseRuntimeError(e, this);
}
catch {
}
}
}
else {
// for private items just make the call and eat any exceptions
try {
using (new ApplicationImpersonationContext()) {
callback(_key, _value, reason);
}
}
catch {
}
}
}
/*
* Close the item to complete its removal from cache.
*
* @param reason The reason the item is removed.
*/
internal void Close(CacheItemRemovedReason reason) {
Debug.Assert(State == EntryState.RemovedFromCache, "State == EntryState.RemovedFromCache");
State = EntryState.Closed;
object onRemovedTargets = null;
object[] targets = null;
lock (this) {
if (_onRemovedTargets != null) {
onRemovedTargets = _onRemovedTargets;
if (onRemovedTargets is Hashtable) {
ICollection col = ((Hashtable) onRemovedTargets).Keys;
targets = new object[col.Count];
col.CopyTo(targets, 0);
}
}
}
if (onRemovedTargets != null) {
if (targets != null) {
foreach (object target in targets) {
if (target is CacheDependency) {
((CacheDependency)target).ItemRemoved();
}
else {
CallCacheItemRemovedCallback((CacheItemRemovedCallback) target, reason);
}
}
}
else if (onRemovedTargets is CacheItemRemovedCallback) {
CallCacheItemRemovedCallback((CacheItemRemovedCallback) onRemovedTargets, reason);
}
else {
((CacheDependency) onRemovedTargets).ItemRemoved();
}
}
if (_dependency != null) {
_dependency.DisposeInternal();
}
}
#if DBG
internal /*public*/ string DebugDescription(string indent) {
StringBuilder sb = new StringBuilder();
String nlindent = "\n" + indent + " ";
sb.Append(indent + "CacheItem");
sb.Append(nlindent); sb.Append("_key="); sb.Append(_key);
sb.Append(nlindent); sb.Append("_value="); sb.Append(Debug.GetDescription(_value, indent));
sb.Append(nlindent); sb.Append("_utcExpires="); sb.Append(Debug.FormatUtcDate(_utcExpires));
sb.Append(nlindent); sb.Append("_bits=0x"); sb.Append(((int)_bits).ToString("x", CultureInfo.InvariantCulture));
sb.Append("\n");
return sb.ToString();
}
#endif
internal void AddCacheDependencyNotify(CacheDependency dependency) {
lock (this) {
if (_onRemovedTargets == null) {
_onRemovedTargets = dependency;
}
else if (_onRemovedTargets is Hashtable) {
Hashtable h = (Hashtable) _onRemovedTargets;
h[dependency] = dependency;
}
else {
Hashtable h = new Hashtable(2);
h[_onRemovedTargets] = _onRemovedTargets;
h[dependency] = dependency;
_onRemovedTargets = h;
}
}
}
internal void RemoveCacheDependencyNotify(CacheDependency dependency) {
lock (this) {
if (_onRemovedTargets != null) {
if (_onRemovedTargets == dependency) {
_onRemovedTargets = null;
}
else {
// We assume the dependency must exist, so we don't need
// to test for a cast.
Hashtable h = (Hashtable) _onRemovedTargets;
h.Remove(dependency);
if (h.Count == 0) {
_onRemovedTargets = null;
}
}
}
}
}
#if USE_MEMORY_CACHE
internal CacheItemRemovedCallback CacheItemRemovedCallback {
get {
CacheItemRemovedCallback callback = null;
lock (this) {
if (_onRemovedTargets != null) {
if (_onRemovedTargets is Hashtable) {
foreach (DictionaryEntry e in (Hashtable)_onRemovedTargets) {
callback = e.Value as CacheItemRemovedCallback;
break;
}
}
else {
callback = _onRemovedTargets as CacheItemRemovedCallback;
}
}
}
return callback;
}
}
#endif
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,50 @@
// <copyright file="DependencyChangeMonitor.cs" company="Microsoft">
// Copyright (c) 2009 Microsoft Corporation. All rights reserved.
// </copyright>
#if USE_MEMORY_CACHE
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.Caching;
using System.Web.Util;
namespace System.Web.Caching {
internal sealed class DependencyChangeMonitor: ChangeMonitor, ICacheDependencyChanged {
private CacheDependency _dependency;
public override string UniqueId {
get {
return _dependency.GetUniqueID();
}
}
internal DependencyChangeMonitor(CacheDependency dependency) {
if (dependency == null) {
throw new ArgumentNullException("dependency");
}
if (!dependency.Use()) {
throw new InvalidOperationException(
SR.GetString(SR.Cache_dependency_used_more_that_once));
}
_dependency = dependency;
_dependency.SetCacheDependencyChanged(this);
if (_dependency.HasChanged) {
OnChanged(null);
}
InitializationComplete();
}
void ICacheDependencyChanged.DependencyChanged(Object sender, EventArgs e) {
OnChanged(null);
}
[SuppressMessage("Microsoft.Usage", "CA2215:DisposeMethodsShouldCallBaseClassDispose", Justification="suppressed because fxcop is suffering from despotism")]
protected override void Dispose(bool disposing) {
if (disposing) {
if (_dependency != null) {
_dependency.DisposeInternal();
}
}
}
}
}
#endif

View File

@@ -0,0 +1,33 @@
using System;
using System.Security.Permissions;
using System.Web;
using System.Web.Caching;
namespace System.Web.Caching {
[Serializable]
[AspNetHostingPermission(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Unrestricted)]
public class FileResponseElement: ResponseElement {
private String _path;
private long _offset;
private long _length;
public String Path { get { return _path; } }
public long Offset { get { return _offset; } }
public long Length { get { return _length; } }
private FileResponseElement() { } // hide default constructor
public FileResponseElement(String path, long offset, long length) {
if (path == null)
throw new ArgumentNullException("path");
if (offset < 0)
throw new ArgumentOutOfRangeException("offset");
if (length < 0)
throw new ArgumentOutOfRangeException("length");
_path = path;
_offset = offset;
_length = length;
}
}
}

View File

@@ -0,0 +1,28 @@
using System;
using System.Security.Permissions;
using System.Web;
using System.Web.Caching;
namespace System.Web.Caching {
// A header element holds the header name and value.
[Serializable]
public sealed class HeaderElement {
private string _name;
private string _value;
public string Name { get { return _name; } }
public string Value { get { return _value; } }
private HeaderElement() { } // hide default constructor
public HeaderElement(string name, string value) {
if (name == null)
throw new ArgumentNullException("name");
if (value == null)
throw new ArgumentNullException("value");
_name = name;
_value = value;
}
}
}

View File

@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Security.Permissions;
using System.Web;
namespace System.Web.Caching {
public interface IOutputCacheEntry {
[SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly", Justification = "This can be set by the user to support inline dictionary intializers")]
List<HeaderElement> HeaderElements { get; set; }
[SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly", Justification = "This can be set by the user to support inline dictionary intializers")]
List<ResponseElement> ResponseElements { get; set; }
}
}

View File

@@ -0,0 +1,198 @@
// <copyright file="MemCache.cs" company="Microsoft">
// Copyright (c) 2009 Microsoft Corporation. All rights reserved.
// </copyright>
#if USE_MEMORY_CACHE
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Globalization;
using System.Security;
using System.Security.Permissions;
using System.Reflection;
using System.Runtime.Caching;
using System.Text;
using System.Web.Configuration;
using System.Web.Util;
namespace System.Web.Caching {
internal sealed class MemCache: CacheInternal {
private volatile bool _inited;
private static object _initLock = new object();
private MemoryCache _cacheInternal;
private MemoryCache _cachePublic;
private volatile bool _disposed;
internal MemCache(CacheCommon cacheCommon) : base(cacheCommon) {
// config initialization is done by Init.
Assembly asm = Assembly.Load("System.Runtime.Caching, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL");
Type t = asm.GetType("System.Runtime.Caching.MemoryCache", true, false);
_cacheInternal = HttpRuntime.CreateNonPublicInstance(t, new object[] {"asp_icache", null, true}) as MemoryCache;
_cachePublic = HttpRuntime.CreateNonPublicInstance(t, new object[] {"asp_pcache", null, true}) as MemoryCache;
}
protected override void Dispose(bool disposing) {
try {
_disposed = true;
if (disposing) {
if (_cacheInternal != null) {
_cacheInternal.Dispose();
}
if (_cachePublic != null) {
_cachePublic.Dispose();
}
}
}
finally {
base.Dispose(disposing);
}
}
internal override int PublicCount {
get {
return (_cachePublic != null) ? (int)_cachePublic.GetCount() : 0;
}
}
internal override long TotalCount {
get {
long internalCount = (_cacheInternal != null) ? _cacheInternal.GetCount(null) : 0;
return internalCount + PublicCount;
}
}
internal void Init(CacheSection cacheSection) {
if (_inited) {
return;
}
lock (_initLock) {
if (_inited) {
return;
}
NameValueCollection config = null;
if (cacheSection != null) {
//_enableMemoryCollection = (!cacheSection.DisableMemoryCollection);
//_enableExpiration = (!cacheSection.DisableExpiration);
int physicalMemoryLimitPercentage = cacheSection.PercentagePhysicalMemoryUsedLimit;
long cacheMemoryLimitMegabytes = cacheSection.PrivateBytesLimit << 20;
TimeSpan pollingInterval = cacheSection.PrivateBytesPollTime;
config = new NameValueCollection(3);
config["physicalMemoryLimitPercentage"] = physicalMemoryLimitPercentage.ToString(CultureInfo.InvariantCulture);
config["cacheMemoryLimitMegabytes"] = cacheMemoryLimitMegabytes.ToString(CultureInfo.InvariantCulture);
config["pollingInterval"] = pollingInterval.ToString();
}
Type t = _cacheInternal.GetType();
t.InvokeMember("UpdateConfig",
BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.InvokeMethod,
null, // binder
_cacheInternal, // target
new object[] {config}, // args
CultureInfo.InvariantCulture);
t.InvokeMember("UpdateConfig",
BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.InvokeMethod,
null, // binder
_cachePublic, // target
new object[] {config}, // args
CultureInfo.InvariantCulture);
_inited = true;
}
}
// return enumerator for public entries
internal override IDictionaryEnumerator CreateEnumerator() {
return (IDictionaryEnumerator)((IEnumerable)_cachePublic).GetEnumerator();
}
internal CacheEntryChangeMonitor CreateCacheEntryChangeMonitor(IEnumerable<String> keys, bool isPublic) {
return (isPublic) ? _cachePublic.CreateCacheEntryChangeMonitor(keys, null) : _cacheInternal.CreateCacheEntryChangeMonitor(keys, null);
}
private CacheItemPolicy GetPolicy(CacheEntry newEntry) {
CacheItemPolicy policy = new CacheItemPolicy();
policy.SlidingExpiration = newEntry.SlidingExpiration;
if (policy.SlidingExpiration == ObjectCache.NoSlidingExpiration) {
policy.AbsoluteExpiration = (newEntry.UtcExpires != Cache.NoAbsoluteExpiration) ? newEntry.UtcExpires : ObjectCache.InfiniteAbsoluteExpiration;
}
if (newEntry.Dependency != null) {
policy.ChangeMonitors.Add(new DependencyChangeMonitor(newEntry.Dependency));
}
policy.Priority = (newEntry.UsageBucket == 0xff) ? System.Runtime.Caching.CacheItemPriority.NotRemovable : System.Runtime.Caching.CacheItemPriority.Default;
CacheItemRemovedCallback callback = newEntry.CacheItemRemovedCallback;
if (callback != null) {
policy.RemovedCallback = (new RemovedCallback(callback)).CacheEntryRemovedCallback;
}
return policy;
}
internal override CacheEntry UpdateCache(CacheKey cacheKey,
CacheEntry newEntry,
bool replace,
CacheItemRemovedReason removedReason,
out object valueOld) {
valueOld = null;
CacheEntry entry = null;
string key = cacheKey.Key;
bool isPublic = cacheKey.IsPublic;
if (_disposed) {
return null;
}
MemoryCache cache = (isPublic) ? _cachePublic : _cacheInternal;
if (newEntry == null && !replace) {
// get
object o = cache.Get(key);
if (o != null) {
entry = new CacheEntry(key, o, null, null,
Cache.NoAbsoluteExpiration, Cache.NoSlidingExpiration,
CacheItemPriority.Default, isPublic);
entry.State = CacheEntry.EntryState.AddedToCache;
}
}
else if (newEntry != null && replace) {
// set
try {
}
finally {
// prevent ThreadAbortEx from interrupting these calls
CacheItemPolicy policy = GetPolicy(newEntry);
cache.Set(key, newEntry.Value, policy);
}
}
else if (newEntry != null && !replace) {
// add
try {
}
finally {
// prevent ThreadAbortEx from interrupting these calls
CacheItemPolicy policy = GetPolicy(newEntry);
Object o = cache.AddOrGetExisting(key, newEntry.Value, policy);
if (o != null) {
entry = new CacheEntry(key, o, null, null,
Cache.NoAbsoluteExpiration, Cache.NoSlidingExpiration,
CacheItemPriority.Default, isPublic);
entry.State = CacheEntry.EntryState.AddedToCache;
}
}
}
else {
// remove
valueOld = cache.Remove(key);
}
return entry;
}
internal override long TrimIfNecessary(int percent) {
return _cachePublic.Trim(percent) + _cacheInternal.Trim(percent);
}
internal override void EnableExpirationTimer(bool enable) {
// This is done by Dispose, so it's a no-op here
}
}
}
#endif

View File

@@ -0,0 +1,28 @@
using System;
using System.Security.Permissions;
using System.Web;
using System.Web.Caching;
namespace System.Web.Caching {
[Serializable]
[AspNetHostingPermission(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Unrestricted)]
public class MemoryResponseElement: ResponseElement {
private byte[] _buffer;
private long _length;
public byte[] Buffer { get { return _buffer; } }
public long Length { get { return _length; } }
private MemoryResponseElement() { } // hide default constructor
public MemoryResponseElement(byte[] buffer, long length) {
if (buffer == null)
throw new ArgumentNullException("buffer");
if (length < 0 || length > buffer.Length)
throw new ArgumentOutOfRangeException("length");
_buffer = buffer;
_length = length;
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,60 @@
using System;
using System.Collections.Generic;
using System.Security.Permissions;
using System.Web;
namespace System.Web.Caching {
[Serializable]
internal class OutputCacheEntry: IOutputCacheEntry {
// fields that hold metadata for the entry
private Guid _cachedVaryId;
private HttpCachePolicySettings _settings;
private string _kernelCacheUrl;
private string _dependenciesKey;
private string[] _dependencies; // file dependencies
//response fields
private int _statusCode;
private String _statusDescription;
private List<HeaderElement> _headerElements;
private List<ResponseElement> _responseElements;
internal Guid CachedVaryId { get { return _cachedVaryId; } }
internal HttpCachePolicySettings Settings { get { return _settings; } }
internal string KernelCacheUrl { get { return _kernelCacheUrl; } }
internal string DependenciesKey { get { return _dependenciesKey; } }
internal string[] Dependencies { get { return _dependencies; } }
internal int StatusCode { get { return _statusCode; } }
internal string StatusDescription { get { return _statusDescription; } }
public List<HeaderElement> HeaderElements { get { return _headerElements; }
set { _headerElements = value; } }
public List<ResponseElement> ResponseElements { get { return _responseElements; }
set { _responseElements = value; } }
private OutputCacheEntry() {
// hide default constructor
}
internal OutputCacheEntry(Guid cachedVaryId,
HttpCachePolicySettings settings,
string kernelCacheUrl,
string dependenciesKey,
string[] dependencies,
int statusCode,
string statusDescription,
List<HeaderElement> headerElements,
List<ResponseElement> responseElements) {
_cachedVaryId = cachedVaryId;
_settings = settings;
_kernelCacheUrl = kernelCacheUrl;
_dependenciesKey = dependenciesKey;
_dependencies = dependencies;
_statusCode = statusCode;
_statusDescription = statusDescription;
_headerElements = headerElements;
_responseElements = responseElements;
}
}
}

View File

@@ -0,0 +1,18 @@
using System;
using System.Configuration.Provider;
using System.Security.Permissions;
using System.Web;
namespace System.Web.Caching {
// the abstract base class implemented by all output cache providers
public abstract class OutputCacheProvider: ProviderBase {
// Returns the specified entry, or null if it does not exist.
public abstract Object Get(String key);
// Inserts the specified entry into the cache if it does not already exist, otherwise returns the existing entry.
public abstract Object Add(String key, Object entry, DateTime utcExpiry);
// Inserts the specified entry into the cache, overwriting an existing entry if present.
public abstract void Set(String key, Object entry, DateTime utcExpiry);
// Removes the specified entry from the cache.
public abstract void Remove(String key);
}
}

View File

@@ -0,0 +1,32 @@
using System;
using System.Configuration.Provider;
using System.Security.Permissions;
using System.Web;
namespace System.Web.Caching {
public sealed class OutputCacheProviderCollection : ProviderCollection {
new public OutputCacheProvider this[string name] {
get {
return (OutputCacheProvider) base[name];
}
}
public override void Add(ProviderBase provider) {
if (provider == null) {
throw new ArgumentNullException( "provider" );
}
if (!(provider is OutputCacheProvider)) {
throw new ArgumentException(SR.GetString(SR.Provider_must_implement_type, typeof(OutputCacheProvider).Name),
"provider");
}
base.Add(provider);
}
public void CopyTo(OutputCacheProvider[] array, int index) {
base.CopyTo(array, index);
}
}
}

View File

@@ -0,0 +1,41 @@
// <copyright file="RemovedCallback.cs" company="Microsoft">
// Copyright (c) 2009 Microsoft Corporation. All rights reserved.
// </copyright>
#if USE_MEMORY_CACHE
using System;
using System.Runtime.Caching;
using System.Web.Util;
namespace System.Web.Caching {
internal sealed class RemovedCallback {
CacheItemRemovedCallback _callback;
internal RemovedCallback(CacheItemRemovedCallback callback) {
_callback = callback;
}
internal void CacheEntryRemovedCallback(CacheEntryRemovedArguments arguments) {
string key = arguments.CacheItem.Key;
object value = arguments.CacheItem.Value;
CacheItemRemovedReason reason;
switch (arguments.RemovedReason) {
case CacheEntryRemovedReason.Removed :
reason = CacheItemRemovedReason.Removed;
break;
case CacheEntryRemovedReason.Expired :
reason = CacheItemRemovedReason.Expired;
break;
case CacheEntryRemovedReason.Evicted :
reason = CacheItemRemovedReason.Underused;
break;
case CacheEntryRemovedReason.ChangeMonitorChanged :
reason = CacheItemRemovedReason.DependencyChanged;
break;
default :
reason = CacheItemRemovedReason.Removed;
break;
}
_callback(key, value, reason);
}
}
}
#endif

View File

@@ -0,0 +1,10 @@
using System;
using System.Security.Permissions;
using System.Web;
using System.Web.Caching;
namespace System.Web.Caching {
[Serializable]
public abstract class ResponseElement {
}
}

View File

@@ -0,0 +1,63 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Security.Permissions;
using System.Web;
namespace System.Web.Caching {
internal class SRef {
private static Type s_type = Type.GetType("System.SizedReference", true, false);
private Object _sizedRef;
internal SRef(Object target) {
_sizedRef = HttpRuntime.CreateNonPublicInstance(s_type, new object[] {target});
}
internal long ApproximateSize {
[PermissionSet(SecurityAction.Assert, Unrestricted=true)]
get {
object o = s_type.InvokeMember("ApproximateSize",
BindingFlags.Public | BindingFlags.Instance | BindingFlags.GetProperty,
null, // binder
_sizedRef, // target
null, // args
CultureInfo.InvariantCulture);
return (long) o;
}
}
[PermissionSet(SecurityAction.Assert, Unrestricted=true)]
internal void Dispose() {
s_type.InvokeMember("Dispose",
BindingFlags.Public | BindingFlags.Instance | BindingFlags.InvokeMethod,
null, // binder
_sizedRef, // target
null, // args
CultureInfo.InvariantCulture);
}
}
internal class SRefMultiple {
private List<SRef> _srefs = new List<SRef>();
internal void AddSRefTarget(Object o) {
_srefs.Add(new SRef(o));
}
internal long ApproximateSize {
[PermissionSet(SecurityAction.Assert, Unrestricted = true)]
get {
return _srefs.Sum(s => s.ApproximateSize);
}
}
[PermissionSet(SecurityAction.Assert, Unrestricted = true)]
internal void Dispose() {
foreach (SRef s in _srefs) {
s.Dispose();
}
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,42 @@
using System;
using System.Runtime.Serialization;
using System.Security.Permissions;
using System.Web;
using System.Web.Caching;
using System.Web.Compilation;
namespace System.Web.Caching {
[Serializable]
[AspNetHostingPermission(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Unrestricted)]
public class SubstitutionResponseElement: ResponseElement {
[NonSerialized]
private HttpResponseSubstitutionCallback _callback;
private string _targetTypeName;
private string _methodName;
public HttpResponseSubstitutionCallback Callback { get { return _callback; } }
private SubstitutionResponseElement() { } // hide default constructor
public SubstitutionResponseElement(HttpResponseSubstitutionCallback callback) {
if (callback == null)
throw new ArgumentNullException("callback");
_callback = callback;
}
[OnSerializing()]
private void OnSerializingMethod(StreamingContext context) {
// create a string representation of the callback
_targetTypeName = System.Web.UI.Util.GetAssemblyQualifiedTypeName(_callback.Method.ReflectedType);
_methodName = _callback.Method.Name;
}
[OnDeserialized()]
private void OnDeserializedMethod(StreamingContext context) {
// re-create each ValidationCallbackInfo from its string representation
Type target = BuildManager.GetType(_targetTypeName, true /*throwOnFail*/, false /*ignoreCase*/);
_callback = (HttpResponseSubstitutionCallback) Delegate.CreateDelegate(typeof(HttpResponseSubstitutionCallback), target, _methodName);
}
}
}

File diff suppressed because it is too large Load Diff