Exemple #1
0
        public void Insert(ICachePackage package)
        {
            if (HttpContext.Current == null)
            {
                throw new Exception("HttpContext.Current is null");
            }

            HttpContext.Current.Cache.Insert(package.Key, package);
        }
 public void Insert(ICachePackage package)
 {
     if (Cache.Keys.Any(p => p == package.Key))
     {
         Cache[package.Key] = package;
     }
     else
     {
         Cache.Add(package.Key, package);
     }
 }
Exemple #3
0
        internal HttpWebRequest GetPreparedWebRequest(string method)
        {
            if (_request == null)
            {
                _request        = PrepareBaseRequest();
                _request.Method = method;

                if (_request.Method == "GET")
                {
                    CachePackage = Api.ResponseCache.Get(GetCacheKey());
                    if (CachePackage != null)
                    {
                        if (CachePackage.LastModified != DateTime.MinValue)
                        {
                            _request.IfModifiedSince = CachePackage.LastModified;
                        }
                        if (!string.IsNullOrWhiteSpace(CachePackage.ETag))
                        {
                            _request.Headers.Add(HttpRequestHeader.IfNoneMatch, CachePackage.ETag);
                        }
                    }
                }

                if (!string.IsNullOrWhiteSpace(RequestBody))
                {
                    using (var writer = new StreamWriter(_request.GetRequestStream()))
                    {
                        writer.Write(RequestBody);
                    }
                    _request.ContentType = ContentType;
                }

                if (ContentLength > 0)
                {
                    _request.ContentLength = ContentLength;
                }
            }

            return(_request);
        }