Пример #1
0
 public Stream Read(CacheVariable variable)
 {
     byte[] buffer = null;
     if (_contentData.TryGetValue(variable.UniqueCode, out buffer))
     {
         return(new MemoryStream(buffer));
     }
     return(null);
 }
Пример #2
0
        public void Delete(CacheVariable variable)
        {
            const string sql  = "delete from dbo.cache where code=@code";
            var          prms = SqlHelper.CreateParameters((c) =>
            {
                c.Add("@code", variable.UniqueCode);
            });

            SqlHelper.ExecuteCommandText("db-cache", sql, prms);
        }
Пример #3
0
        /// <summary>
        /// 更新缓存器内容
        /// </summary>
        /// <param name="variable"></param>
        public void Update(CacheVariable variable, Stream content)
        {
            if (content.Length > int.MaxValue)
            {
                throw new WebCacheException("MemoryStorage无法存储超过" + int.MaxValue + "个字节的缓存内容!");
            }

            byte[] buffer = new byte[content.Length];
            content.ReadPro(buffer, 0, (int)content.Length);

            _contentData.AddOrUpdate(variable.UniqueCode, buffer, (key, value) => buffer);
            _modifiedData.AddOrUpdate(variable.UniqueCode, DateTime.Now, (key, value) => DateTime.Now);
        }
Пример #4
0
        public void Delete(CacheVariable variable)
        {
            var host   = new WebHost(variable.Url);
            var target = string.Format("{0}://{1}/cache/memory.htm?code={2}", host.Protocol, host.Host, HttpUtility.UrlEncode(variable.UniqueCode, Encoding.UTF8));

            using (WebClient client = new WebClient())
            {
                try
                {
                    client.DownloadData(target);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
Пример #5
0
        /// <summary>
        /// 更新缓存器内容
        /// </summary>
        /// <param name="url"></param>
        public void Update(CacheVariable variable, Stream content)
        {
            if (content.Length > int.MaxValue)
            {
                throw new WebCacheException("SqlCacheStorage无法存储超过" + int.MaxValue + "个字节的缓存内容!");
            }

            byte[] buffer = new byte[content.Length];
            content.ReadPro(buffer, 0, (int)content.Length);

            var prms = SqlHelper.CreateParameters((c) =>
            {
                c.Add("@code", variable.UniqueCode);
                c.Add("@cont", buffer);
            });

            SqlData data = SqlHelper.ExecuteCommandText("db-cache", _updateContentSql, prms);
        }
Пример #6
0
        public Stream Read(CacheVariable variable)
        {
            const string sql  = "select cont from dbo.cache where code=@code";
            var          prms = SqlHelper.CreateParameters((c) =>
            {
                c.Add("@code", variable.UniqueCode);
            });

            SqlData data = SqlHelper.ExecuteCommandText("db-cache", sql, prms);

            if (data.IsEmpty())
            {
                return(null);
            }

            byte[] buffer = data.GetScalar <byte[]>();
            return(new MemoryStream(buffer));
        }
Пример #7
0
        public bool TryGetLastModified(CacheVariable variable, out DateTime lastModified)
        {
            lastModified = DateTime.Now;
            const string sql  = "select lastModified from dbo.cache where code=@code";
            var          prms = SqlHelper.CreateParameters((c) =>
            {
                c.Add("@code", variable.UniqueCode);
            });

            SqlData data = SqlHelper.ExecuteCommandText("db-cache", sql, prms);

            if (data.IsEmpty())
            {
                return(false);
            }

            lastModified = data.GetScalar <DateTime>();
            return(true);
        }
Пример #8
0
 public void Delete(CacheVariable variable)
 {
 }
Пример #9
0
 /// <summary>
 /// 更新缓存器内容
 /// </summary>
 /// <param name="variable"></param>
 public void Update(CacheVariable variable, Stream content)
 {
 }
Пример #10
0
 public Stream Read(CacheVariable variable)
 {
     return(null);
 }
Пример #11
0
 public bool TryGetLastModified(CacheVariable variable, out DateTime lastModified)
 {
     lastModified = DateTime.Now;
     return(false);
 }
Пример #12
0
        /// <summary>
        /// 向缓存区中写入信息
        /// </summary>
        /// <param name="content"></param>
        public override void Write(WebPageContext context, Stream content, ICacheStorage storage)
        {
            var variable = new CacheVariable(GetUrl(context), context.CompressionType, context.Device);

            storage.Update(variable, content);
        }
Пример #13
0
        /// <summary>
        /// 读取缓存区中的流信息
        /// </summary>
        /// <returns></returns>
        public override Stream Read(WebPageContext context, ICacheStorage storage)
        {
            var variable = new CacheVariable(GetUrl(context), context.CompressionType, context.Device);

            return(storage.Read(variable));
        }
Пример #14
0
        protected bool TryGetCacheTime(WebPageContext context, out DateTime cacheTime, ICacheStorage storage)
        {
            var variable = new CacheVariable(GetUrl(context), context.CompressionType, context.Device);

            return(storage.TryGetLastModified(variable, out cacheTime));
        }
Пример #15
0
 public bool TryGetLastModified(CacheVariable variable, out DateTime lastModified)
 {
     return(_modifiedData.TryGetValue(variable.UniqueCode, out lastModified));
 }