2 Copyright (c) Microsoft Corporation
9 The class implements the app domain wide configuration
10 for request cache aware clients
14 Alexei Vopilov 21-Dec-2002
18 Jan 25 2004 - Changed the visibility of the class from public to internal, compressed unused logic.
21 namespace System.Net.Cache {
23 using System.Collections;
24 using System.Net.Configuration;
25 using System.Configuration;
28 /// <summary> Specifies app domain-wide default settings for request caching </summary>
29 internal sealed class RequestCacheManager {
30 private RequestCacheManager() {}
32 private static volatile RequestCachingSectionInternal s_CacheConfigSettings;
34 private static readonly RequestCacheBinding s_BypassCacheBinding = new RequestCacheBinding (null, null, new RequestCachePolicy(RequestCacheLevel.BypassCache));
36 private static volatile RequestCacheBinding s_DefaultGlobalBinding;
37 private static volatile RequestCacheBinding s_DefaultHttpBinding;
38 private static volatile RequestCacheBinding s_DefaultFtpBinding;
41 // ATN: the caller MUST use uri.Scheme as a parameter, otheriwse cannot do schme ref comparision
43 internal static RequestCacheBinding GetBinding(string internedScheme)
45 if (internedScheme == null)
46 throw new ArgumentNullException("uriScheme");
48 if (s_CacheConfigSettings == null)
51 if(s_CacheConfigSettings.DisableAllCaching)
52 return s_BypassCacheBinding;
54 if (internedScheme.Length == 0)
55 return s_DefaultGlobalBinding;
57 if ((object)internedScheme == (object)Uri.UriSchemeHttp || (object)internedScheme == (object)Uri.UriSchemeHttps)
58 return s_DefaultHttpBinding;
60 if ((object)internedScheme == (object)Uri.UriSchemeFtp)
61 return s_DefaultFtpBinding;
63 return s_BypassCacheBinding;
66 internal static bool IsCachingEnabled
70 if (s_CacheConfigSettings == null)
73 return !s_CacheConfigSettings.DisableAllCaching;
78 internal static void SetBinding(string uriScheme, RequestCacheBinding binding)
80 if (uriScheme == null)
81 throw new ArgumentNullException("uriScheme");
83 if (s_CacheConfigSettings == null)
86 if(s_CacheConfigSettings.DisableAllCaching)
89 if (uriScheme.Length == 0)
90 s_DefaultGlobalBinding = binding;
91 else if (uriScheme == Uri.UriSchemeHttp || uriScheme == Uri.UriSchemeHttps)
92 s_DefaultHttpBinding = binding;
93 else if (uriScheme == Uri.UriSchemeFtp)
94 s_DefaultFtpBinding = binding;
97 private static void LoadConfigSettings()
99 // Any concurent access shall go here and block until we've grabbed the config settings
100 lock (s_BypassCacheBinding)
102 if (s_CacheConfigSettings == null)
105 var settings = new RequestCachingSectionInternal();
107 RequestCachingSectionInternal settings = RequestCachingSectionInternal.GetSection();
109 s_DefaultGlobalBinding = new RequestCacheBinding (settings.DefaultCache, settings.DefaultHttpValidator, settings.DefaultCachePolicy);
110 s_DefaultHttpBinding = new RequestCacheBinding (settings.DefaultCache, settings.DefaultHttpValidator, settings.DefaultHttpCachePolicy);
111 s_DefaultFtpBinding = new RequestCacheBinding (settings.DefaultCache, settings.DefaultFtpValidator, settings.DefaultFtpCachePolicy);
114 s_CacheConfigSettings = settings;
121 class RequestCacheValidator
123 public object CreateValidator ()
125 throw new NotImplementedException ();
129 class RequestCachingSectionInternal
132 public readonly bool DisableAllCaching = true;
138 internal class RequestCacheBinding {
139 private RequestCache m_RequestCache;
140 private RequestCacheValidator m_CacheValidator;
141 private RequestCachePolicy m_Policy;
144 internal RequestCacheBinding (RequestCache requestCache, RequestCacheValidator cacheValidator, RequestCachePolicy policy) {
145 m_RequestCache = requestCache;
146 m_CacheValidator = cacheValidator;
150 internal RequestCache Cache {
151 get {return m_RequestCache;}
154 internal RequestCacheValidator Validator {
155 get {return m_CacheValidator;}
158 internal RequestCachePolicy Policy {
159 get {return m_Policy;}