Exemple #1
0
        /// <summary>
        /// 尝试设置 ETag 标签
        /// </summary>
        /// <param name="cachePolicy"></param>
        public bool TrySetETag(ClientCachePolicyBase cachePolicy)
        {
            if (ETag == null)
            {
                return(false);
            }

            cachePolicy.SetETag(ETag);
            return(true);
        }
Exemple #2
0
        /// <summary>
        /// 根据缓存项的设置,设置客户端的 maxage 缓存策略
        /// </summary>
        /// <param name="cachePolicy"></param>
        /// <param name="shake"></param>
        public void SetMaxAge(ClientCachePolicyBase cachePolicy, TimeSpan shake)
        {
            var delta = Expiration - DateTime.UtcNow;

            if (delta <= TimeSpan.Zero)
            {
                cachePolicy.SetMaxAge(TimeSpan.Zero);
                return;
            }


            var random = new Random(DateTime.Now.Millisecond);
            var offset = TimeSpan.FromMilliseconds(random.NextDouble() * shake.TotalMilliseconds);

            var age = delta + offset;

            cachePolicy.SetMaxAge(age);
        }
Exemple #3
0
 /// <summary>
 /// 应用客户端缓存策略
 /// </summary>
 /// <param name="cachePolicy"></param>
 public void ApplyClientCachePolicy(ClientCachePolicyBase cachePolicy)
 {
     TrySetETag(cachePolicy);
     SetMaxAge(cachePolicy);
 }
Exemple #4
0
        /// <summary>
        /// 根据缓存项的设置,设置客户端的 maxage 缓存策略
        /// </summary>
        /// <param name="cachePolicy"></param>
        public void SetMaxAge(ClientCachePolicyBase cachePolicy)
        {
            var shake = Math.Min(DurationWhenCreated.TotalMilliseconds / 50, maxShake.TotalMilliseconds);

            SetMaxAge(cachePolicy, TimeSpan.FromMilliseconds(shake));
        }