Beispiel #1
0
    /// <summary>
    /// 创建一个自定义的缓存优先级
    /// </summary>
    /// <param name="priority">预制优先级,当缓存提供程序无法识别缓存优先级提示时使用</param>
    /// <param name="hint">缓存优先级提示信息,特定的缓存提供程序可以读取该信息使用最合适的优先级</param>
    /// <returns></returns>
    public CachePriority CreatePriority( CachePriority priority, string hint )
    {
      if ( priority._hint != null )
        throw new ArgumentException( "priority" );

      return new CachePriority( priority._priorityValue, hint );
    }
Beispiel #2
0
        /// <summary>
        /// 创建一个自定义的缓存优先级
        /// </summary>
        /// <param name="priority">预制优先级,当缓存提供程序无法识别缓存优先级提示时使用</param>
        /// <param name="hint">缓存优先级提示信息,特定的缓存提供程序可以读取该信息使用最合适的优先级</param>
        /// <returns></returns>
        public CachePriority CreatePriority(CachePriority priority, string hint)
        {
            if (priority._hint != null)
            {
                throw new ArgumentException("priority");
            }

            return(new CachePriority(priority._priorityValue, hint));
        }
        /// <summary>
        /// 创建缓存策略
        /// </summary>
        /// <param name="expires">过期时间</param>
        /// <param name="dependencies">缓存依赖项</param>
        /// <param name="priority">缓存优先级</param>
        public CachePolicyItem(DateTime expires, CacheDependency dependencies = null, CachePriority priority = default(CachePriority))
        {
            if (expires.Kind != DateTimeKind.Utc)
            {
                throw new ArgumentException("expires must be an UTC time.", "expires");
            }


            Expires      = expires;
            Priority     = priority;
            Dependencies = dependencies;
        }
Beispiel #4
0
            public static CachePolicyProviderWithPriority Create(CachePolicy policy, CachePriority priority)
            {
                var withPriority = policy as CachePolicyProviderWithPriority;

                if (withPriority != null)
                {
                    return(new CachePolicyProviderWithPriority(withPriority._policy, priority));
                }

                else
                {
                    return(new CachePolicyProviderWithPriority(policy, priority));
                }
            }
        /// <summary>
        /// 从字符串中解析出缓存策略对象
        /// </summary>
        /// <param name="str">要解析的字符串</param>
        /// <returns>缓存策略对象</returns>
        public static CachePolicyItem Parse(string str)
        {
            if (str == null)
            {
                throw new ArgumentNullException(str);
            }

            var data = str.Split(',');

            if (data.Length != 2)
            {
                throw new FormatException();
            }

            var expires  = long.Parse(data[0]);
            var prioroty = CachePriority.Parse(data[1]);


            return(new CachePolicyItem(new DateTime(expires, DateTimeKind.Utc), null, prioroty));
        }
Beispiel #6
0
 /// <summary>
 /// 重写 Equals 方法,比较两个缓存优先级对象(注意,只要预置的优先级一样,就会判定两个对象相同,将忽略缓存优先级提示信息)
 /// </summary>
 /// <param name="priority">要比较的对象</param>
 /// <returns>是否具有同等的优先级</returns>
 public bool Equals(CachePriority priority)
 {
     return(priority._priorityValue == this._priorityValue);
 }
Beispiel #7
0
 private CachePolicyProviderWithPriority(CachePolicy policy, CachePriority priority)
 {
     _policy   = policy;
     _priority = priority;
 }
Beispiel #8
0
 /// <summary>
 /// 创建一个新的缓存策略,使用指定的优先级
 /// </summary>
 /// <param name="priority">默认缓存优先级</param>
 /// <returns>应用了默认缓存优先级的缓存策略提供程序</returns>
 public CachePolicy WithPriority(CachePriority priority)
 {
     return(CachePolicyProviderWithPriority.Create(this, priority));
 }
Beispiel #9
0
 /// <summary>
 /// 重写 Equals 方法,比较两个缓存优先级对象(注意,只要预置的优先级一样,就会判定两个对象相同,将忽略缓存优先级提示信息)
 /// </summary>
 /// <param name="priority">要比较的对象</param>
 /// <returns>是否具有同等的优先级</returns>
 public bool Equals( CachePriority priority )
 {
   return priority._priorityValue == this._priorityValue;
 }
 /// <summary>
 /// 将缓存优先级设置为自定义优先级
 /// </summary>
 /// <param name="priority">自定义优先级</param>
 /// <returns>设置为自定义优先级之后的缓存策略</returns>
 public CachePolicyItem SetPriority(CachePriority priority)
 {
     return(new CachePolicyItem(Expires, Dependencies, priority));
 }