示例#1
0
文件: PageCache.cs 项目: sgww/cozy
 public void Update(string key, CacheBlock block)
 {
     lock (Locker)
     {
         CachePool.Update(key, block);
     }
 }
示例#2
0
文件: PageCache.cs 项目: xxy1991/cozy
 public void Update(string key, CacheBlock block)
 {
     lock (Locker)
     {
         CachePool.Update(key, block);
     }
 }
示例#3
0
        public MarkdownResponse(string path)
        {
            StatusCode  = HttpStatusCode.OK;
            ContentType = "text/html; charset=utf-8";

            Contents    = stream =>
            {
                using (var writer = new StreamWriter(stream))
                {
                    FileInfo fi = new FileInfo(path);
                    var cache   = CacheManager.Instance.MarkdownCache.GetCache(path);

                    if (cache != null && cache.IsEffective(fi))
                    {
                        // Using Cache
                        writer.Write(cache.Data);
                        return;
                    }

                    // Cache miss
                    string context      = null;
                    using (var fs = new FileStream(path, FileMode.Open, FileAccess.Read))
                    {
                        using (var reader = new StreamReader(fs, Encoding.UTF8))
                        {
                            context = CommonMarkConverter.Convert(reader.ReadToEnd());
                            writer.Write(context);
                        }
                    }

                    // cache update
                    if (cache == null) cache = new CacheBlock();
                    cache.Update(context, fi);
                    CacheManager.Instance.MarkdownCache.Update(path, cache);
                }
            };
        }