public virtual IClientCache Create(WebPageContext context) { var value = context.GetConfigValue <string>("Page", "ClientCache", string.Empty).ToLower(); if (!string.IsNullOrEmpty(value)) { switch (value) { case "forever": return(ForeverClientCache.Instance); case "delay": return(DelayClientCache.Instance); default: return(NonClientCache.Instance); } } //通过后缀名获取 IClientCache cache = null; if (_caches.TryGetValue(context.PathExtension, out cache)) { return(cache); } return(NonClientCache.Instance); }
public HttpSendTransport(IClientCache clientCache, HttpSendSettings sendSettings, IReceiveObserver receiveObserver, ReceiveEndpointContext topology) { _clientCache = clientCache; _sendSettings = sendSettings; _receiveObserver = receiveObserver; _topology = topology; _observers = new SendObservable(); }
public HostConnectorWorker(IClientCache clientCache, IOptionsMonitor <AppConfig> config, ILogger <HostConnectorWorker> logger) { _clientCache = clientCache; _config = config; _logger = logger; }
/// <summary> /// Initializes a new instance of the <see cref="CacheClientFactoryDecorator"/> class. /// </summary> /// <param name="clientFactory">The instance to decorate</param> /// <param name="cache">The instance to cache client instances</param> public CacheClientFactoryDecorator( IClientFactory clientFactory, IClientCache cache) : base(clientFactory) { Argument.NotNull(clientFactory, nameof(clientFactory)); Argument.NotNull(cache, nameof(cache)); _clientFactory = clientFactory; _cache = cache; }
public ReceiveTransport(IServiceBusHost host, ClientSettings settings, IPublishEndpointProvider publishEndpointProvider, ISendEndpointProvider sendEndpointProvider, IClientCache clientCache, IPipe <ClientContext> clientPipe, ReceiveTransportObservable transportObserver) { _host = host; _settings = settings; _publishEndpointProvider = publishEndpointProvider; _sendEndpointProvider = sendEndpointProvider; _clientCache = clientCache; _clientPipe = clientPipe; _observers = new ReceiveObservable(); _transportObservers = transportObserver; }
/// <summary> /// 注册缓存处理器,请保证cache是单例的 /// </summary> /// <param name="extension"></param> /// <param name="cache"></param> public void RegisterCache(string extension, IClientCache cache) { if (!_caches.ContainsKey(extension)) { lock (_caches) { if (!_caches.ContainsKey(extension)) { if (extension.StartsWith(".")) { extension = extension.Substring(1); } _caches.Add(extension, cache); _caches.Add(string.Format(".{0}", extension), cache); } } } }
public static IClientCache Create(WebPageContext context) { IClientCache clientCache = null; var config = WebPagesConfiguration.Global.PageConfig; if (config == null || config.ClientCacheFactory == null) { //没有配置文件设置,那么查看程序集级别的注入 clientCache = InjectionClientCacheFactory.Instance.Create(context); } else { IClientCacheFactory factory = config.ClientCacheFactory.GetInstance <IClientCacheFactory>(); clientCache = factory.Create(context); if (clientCache == null) { clientCache = InjectionClientCacheFactory.Instance.Create(context); //配置文件没有设置的就由系统自动设置 } } return(clientCache); }
protected virtual string ExecuteWithCacheAndSlidingExpiration(IClientCache cache, string url, string key, TimeSpan expiry, Func<IClientCache, string, TimeSpan, string> cacheScheme) { var fetch = cache.Get<string>(CreateCacheKey(key, url)); if (fetch != null) { return fetch; } var result = cacheScheme.Invoke(cache, url, expiry); return result; }
protected virtual string ExecuteWithCache(IClientCache cache, string url, string key, Func<IClientCache, string, string> cacheScheme) { var fetch = cache.Get<string>(CreateCacheKey(key, url)); if (fetch != null) { return fetch; } var result = cacheScheme.Invoke(cache, url); return result; }
protected virtual IAsyncResult ExecutePostOrPutAsync(PostOrPut method, string url, string prefixKey, IClientCache cache, TimeSpan slidingExpiration) { WebResponse = null; byte[] content; var request = BuildPostOrPutWebRequest(method, url, out content); var state = new Pair<WebRequest, Pair<byte[], Triplet<IClientCache, TimeSpan, string>>> { First = request, Second = new Pair<byte[], Triplet<IClientCache, TimeSpan, string>> { First = content, Second = new Triplet<IClientCache, TimeSpan, string> { First = cache, Second = slidingExpiration, Third = prefixKey } } }; var args = new WebQueryRequestEventArgs(url); OnQueryRequest(args); return request.BeginGetRequestStream(PostAsyncRequestCallback, state); }
protected virtual void ExecuteGetAsync(string url, string prefixKey, IClientCache cache, TimeSpan slidingExpiration) { WebResponse = null; var client = CreateWebQueryClient(); var key = CreateCacheKey(prefixKey, url); ThreadPool.QueueUserWorkItem( work => ExecuteGetAsyncAndCacheWithExpiry(cache, key, url, slidingExpiration, client) ); }
// expects real cache key, not prefix private void ExecuteGetAsyncAndCacheWithExpiry(IClientCache cache, string key, string url, TimeSpan slidingExpiration, IWebQueryClient client) { var fetch = cache.Get<string>(key); if (fetch != null) { var args = new WebQueryResponseEventArgs(fetch); OnQueryResponse(args); } else { var state = new Pair<IClientCache, Pair<string, TimeSpan>> { First = cache, Second = new Pair<string, TimeSpan> {First = key, Second = slidingExpiration} }; var args = new WebQueryRequestEventArgs(url); OnQueryRequest(args); client.OpenReadCompleted += client_OpenReadCompleted; client.OpenReadAsync(new Uri(url), state); } }
private string ExecutePostOrPutAndCacheWithExpiry(PostOrPut method, IClientCache cache, string url, string key, TimeSpan slidingExpiration, out WebException exception) { var result = ExecutePostOrPut(method, url, out exception); if (exception == null) { cache.Insert(CreateCacheKey(key, url), result, slidingExpiration); } return result; }
protected virtual string ExecuteGet(string url, string key, IClientCache cache, TimeSpan slidingExpiration, out WebException exception ) { WebException ex = null; var ret = ExecuteWithCacheAndSlidingExpiration(cache, url, key, slidingExpiration, (c, u, e) => ExecuteGetAndCacheWithExpiry(cache, url, key, slidingExpiration, out ex)); exception = ex; return ret; }
public virtual string ExecutePostOrPut( PostOrPut method, string url, string key, IClientCache cache, out WebException exception) { WebException ex = null; var ret = ExecuteWithCache(cache, url, key, (c, u) => ExecutePostOrPutAndCache(method, cache, url, key, out ex)); exception = ex; return ret; }
public virtual void RequestAsync(string url, string key, IClientCache cache, TimeSpan slidingExpiration) { switch (Method) { case WebMethod.Get: ExecuteGetAsync(url, key, cache, slidingExpiration); break; case WebMethod.Post: ExecutePostOrPutAsync(PostOrPut.Post, url, key, cache, slidingExpiration); break; case WebMethod.Put: ExecutePostOrPutAsync(PostOrPut.Put, url, key, cache, slidingExpiration); break; case WebMethod.Delete: ExecuteDeleteAsync(url, key, cache, slidingExpiration); break; default: throw new NotSupportedException( "Unsupported web method: {0}".FormatWith(Method.ToUpper()) ); } }
public static void Register(string extension, IClientCache cache) { InjectionClientCacheFactory.Instance.RegisterCache(extension, cache); }
protected virtual IAsyncResult ExecuteDeleteAsync(string url, string prefixKey, IClientCache cache, DateTime absoluteExpiration) { WebResponse = null; var request = BuildDeleteWebRequest(url); var state = new Pair<WebRequest, Pair<byte[], Triplet<IClientCache, DateTime, string>>> { First = request, Second = new Pair<byte[], Triplet<IClientCache, DateTime, string>> { First = null, Second = new Triplet<IClientCache, DateTime, string> { First = cache, Second = absoluteExpiration, Third = prefixKey } } }; var args = new WebQueryRequestEventArgs(url); OnQueryRequest(args); return request.BeginGetRequestStream(PostAsyncRequestCallback, state); }
protected virtual IAsyncResult ExecuteDeleteAsync(string url, string key, IClientCache cache) { WebResponse = null; var request = BuildDeleteWebRequest(url); var state = new Pair<WebRequest, Triplet<byte[], IClientCache, string>> { First = request, Second = new Triplet<byte[], IClientCache, string> { First = null, Second = cache, Third = key } }; var args = new WebQueryRequestEventArgs(url); OnQueryRequest(args); return request.BeginGetRequestStream(PostAsyncRequestCallback, state); }
private string ExecuteGetAndCacheWithExpiry(IClientCache cache, string url, string key, DateTime absoluteExpiration, out WebException exception) { var result = ExecuteGet(url, out exception ); if (exception == null) { cache.Insert(CreateCacheKey(key, url), result, absoluteExpiration); } return result; }
private string ExecuteGetAndCache(IClientCache cache, string url, string key, out WebException exception ) { var result = ExecuteGet(url, out exception); if (exception == null) { cache.Insert(CreateCacheKey(key, url), result); } return result; }
public virtual string ExecutePostOrPut(PostOrPut method, string url, string key, IClientCache cache, TimeSpan slidingExpiration, out WebException exception ) { WebException ex = null; var ret = ExecuteWithCacheAndSlidingExpiration(cache, url, key, slidingExpiration, (c, u, e) => ExecutePostOrPutAndCacheWithExpiry(method, cache, url, key, slidingExpiration, out ex)); exception = ex; return ret; }
public virtual string Request(string url, string key, IClientCache cache, TimeSpan slidingExpiration, out WebException exception) { switch (Method) { case WebMethod.Get: return ExecuteGet(url, key, cache, slidingExpiration, out exception); case WebMethod.Put: return ExecutePostOrPut(PostOrPut.Put, url, key, cache, slidingExpiration, out exception); case WebMethod.Post: return ExecutePostOrPut(PostOrPut.Post, url, key, cache, slidingExpiration, out exception); case WebMethod.Delete: // todo implement delete with cache (for mocking and completeness) throw new NotImplementedException("HTTP DELETE not supported yet; use HTTP POST instead"); default: throw new NotSupportedException("Unknown web method"); } }
protected virtual string ExecuteGet(string url, string key, IClientCache cache, out WebException exception) { WebException ex = null; var ret = ExecuteWithCache(cache, url, key, (c, u) => ExecuteGetAndCache(cache, url, key, out ex)); exception = ex; return ret; }