public virtual IServerCache Create(WebPageContext context) { var value = context.GetConfigValue <string>("Page", "ServerCache", string.Empty).ToLower(); if (!string.IsNullOrEmpty(value)) { switch (value) { case "forever": return(ForeverServerCache.Instance); case "delay": return(DelayServerCache.Instance); default: return(NonServerCache.Instance); } } //通过后缀名获取 IServerCache cache = null; if (_caches.TryGetValue(context.PathExtension, out cache)) { return(cache); } return(NonServerCache.Instance); }
public AdServerHandler(IServerCache cache) { _cache = cache; _clients = new LinkedList <BufferBlock <ResponseMessageModel> >(); _lock = new ReaderWriterLockSlim(LockRecursionPolicy.NoRecursion); _cache.OnItems += Cache_OnItems; }
/// <summary> /// 注册缓存处理器,请保证cache是单例的 /// </summary> /// <param name="extension"></param> /// <param name="cache"></param> public void RegisterCache(string extension, IServerCache 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); } } } }
private bool TryOutputFromServerCache() { IServerCache server = this.ServerCache; bool cacheIsEffective = false; if (!server.IsExpired(_context, this.Storage)) { //服务器端缓存没有过期 using (Stream stream = server.Read(_context, this.Storage)) { if (stream != null) { _isLoadFromServerCache = true; WebPageWriter.Instance.Write(_context, stream); cacheIsEffective = true; } } } return(cacheIsEffective); }
public static IServerCache Create(WebPageContext context) { IServerCache serverCache = null; var config = WebPagesConfiguration.Global.PageConfig; if (config == null || config.ServerCacheFactory == null) { serverCache = InjectionServerCacheFactory.Instance.Create(context); } else { IServerCacheFactory factory = config.ServerCacheFactory.GetInstance <IServerCacheFactory>(); serverCache = factory.Create(context); if (serverCache == null) { serverCache = NonServerCache.Instance; //配置文件没有设置的就由系统自动设置 } } return(serverCache); }
private static async Task Receive(IInteract context, IServerCache cache, BufferBlock <ResponseMessageModel> messages, CancellationToken token) { var it = context.Receive(); EnumeratorResult <ChunkedStream> messageStream; while ((messageStream = await it.MoveNextAsync(token)).Success) { using (messageStream.Value) { var message = ProtoBuf.Serializer.Deserialize <RequestMessageModel>(messageStream.Value); var items = cache.TryGetItems(message.Keys); if (items.Count > 0) { var mes = ResponseMessageModel.Create(items); if (!messages.Post(mes) && messages.TryReceive(out var last)) { messages.Post(mes); } } } } }
/// <summary> /// 注册缓存处理器,请保证cache是单例的 /// </summary> public static void RegisterCache(string extension, IServerCache cache) { InjectionServerCacheFactory.Instance.RegisterCache(extension, cache); }