Esempio n. 1
0
        /// <summary>
        /// Checks if the client has the current version cached.
        /// </summary>
        /// <param name="context">The HTTP Context</param>
        /// <param name="serverInfo">The service info</param>
        /// <returns>If the client has the same version cached</returns>
        public static bool IsCached(HttpContext context, HttpCacheInfo serverInfo)
        {
            var clientInfo = Get(context);

            if (clientInfo.EntityTag == serverInfo.EntityTag)
            {
                return(true);
            }

            if (clientInfo.LastModified.HasValue)
            {
                return(clientInfo.LastModified.Value >= serverInfo.LastModified.Value);
            }
            return(false);
        }
Esempio n. 2
0
        public static HttpCacheInfo Get(HttpContext context)
        {
            var info = new HttpCacheInfo();

            info.EntityTag = context.Request.Headers["If-None-Match"];

            string lastMod = context.Request.Headers["If-Modified-Since"];

            if (!string.IsNullOrWhiteSpace(lastMod))
            {
                try {
                    info.LastModified = DateTime.Parse(lastMod);
                } catch {}
            }
            return(info);
        }