1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
|
//------------------------------------------------------------------------------
// <copyright file="ControlCachePolicy.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.Web.UI {
using System;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Specialized;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Globalization;
using System.Web;
using System.Web.Util;
using System.Web.UI.WebControls;
using System.Web.Caching;
using System.Security.Permissions;
public sealed class ControlCachePolicy {
private static ControlCachePolicy _cachePolicyStub = new ControlCachePolicy();
private BasePartialCachingControl _pcc;
internal ControlCachePolicy() {
}
internal ControlCachePolicy(BasePartialCachingControl pcc) {
_pcc = pcc;
}
internal static ControlCachePolicy GetCachePolicyStub() {
// Return a stub, which returns SupportsCaching==false and throws on everything else.
return _cachePolicyStub;
}
// Check whether it is valid to access properties on this object
private void CheckValidCallingContext() {
// If it's not being cached, the CachePolicy can't be used
if (_pcc == null) {
throw new HttpException(
SR.GetString(SR.UC_not_cached));
}
// Make sure it's not being used too late
if (_pcc.ControlState >= ControlState.PreRendered) {
throw new HttpException(
SR.GetString(SR.UCCachePolicy_unavailable));
}
}
public bool SupportsCaching {
get {
// Caching is supported if we have a PartialCachingControl
return (_pcc != null);
}
}
public bool Cached {
get {
CheckValidCallingContext();
return !_pcc._cachingDisabled;
}
set {
CheckValidCallingContext();
_pcc._cachingDisabled = !value;
}
}
public TimeSpan Duration {
get {
CheckValidCallingContext();
return _pcc.Duration;
}
set {
CheckValidCallingContext();
_pcc.Duration = value;
}
}
public HttpCacheVaryByParams VaryByParams {
get {
CheckValidCallingContext();
return _pcc.VaryByParams;
}
}
public string VaryByControl {
get {
CheckValidCallingContext();
return _pcc.VaryByControl;
}
set {
CheckValidCallingContext();
_pcc.VaryByControl = value;
}
}
public CacheDependency Dependency {
get {
CheckValidCallingContext();
return _pcc.Dependency;
}
set {
CheckValidCallingContext();
_pcc.Dependency = value;
}
}
public void SetVaryByCustom(string varyByCustom) {
CheckValidCallingContext();
_pcc._varyByCustom = varyByCustom;
}
public void SetSlidingExpiration(bool useSlidingExpiration) {
CheckValidCallingContext();
_pcc._useSlidingExpiration = useSlidingExpiration;
}
public void SetExpires(DateTime expirationTime) {
CheckValidCallingContext();
_pcc._utcExpirationTime = DateTimeUtil.ConvertToUniversalTime(expirationTime);
}
public String ProviderName {
get {
CheckValidCallingContext();
if (_pcc._provider == null) {
return OutputCache.ASPNET_INTERNAL_PROVIDER_NAME;
}
else {
return _pcc._provider;
}
}
set {
CheckValidCallingContext();
if (value == OutputCache.ASPNET_INTERNAL_PROVIDER_NAME) {
value = null;
}
OutputCache.ThrowIfProviderNotFound(value);
_pcc._provider = value;
}
}
}
}
|