/// <summary>
        /// Expires the specified cache tag.
        /// </summary>
        /// <param name="cacheTag">The cache tag.</param>
        /// <returns>
        /// The number of items expired.
        /// </returns>
        public override int Expire(ICacheTag cacheTag)
        {
            string key    = GetTagKey(cacheTag);
            var    item   = new CacheItem(key, DateTimeOffset.UtcNow.Ticks);
            var    policy = new CacheItemPolicy {
                AbsoluteExpiration = ObjectCache.InfiniteAbsoluteExpiration
            };

            MemoryCache.Default.Set(item, policy);
            return(0);
        }
        protected override ICacheTag ReadOneTag(JProperty item)
        {
            ICacheTag cacheTag = base.ReadOneTag(item);

            if (cacheTag is IAllowDefaultIfOptionWithoutValue tagWithNoValueDefault)
            {
                tagWithNoValueDefault.DefaultIfOptionWithoutValue = item.Value.ToString(nameof(IAllowDefaultIfOptionWithoutValue.DefaultIfOptionWithoutValue));
                return cacheTag;
            }

            return cacheTag;
        }
        /// <summary>
        /// Indicates whether the current object is equal to another object of the same type.
        /// </summary>
        /// <param name="other">An object to compare with this object.</param>
        /// <returns>
        /// true if the current object is equal to the <paramref name="other"/> parameter; otherwise, false.
        /// </returns>
        bool Equals(ICacheTag other)
        {
            if (ReferenceEquals(null, other))
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return(string.Equals(other.Tag, Tag, StringComparison.Ordinal));
        }
Пример #4
0
        public static string GetFileFormatExclude(this TemplateInfo info)
        {
            ICacheTag tag = null;

            foreach (string tagName in FileFormattingExcludeTagProvider.TagNames)
            {
                if (info.Tags.TryGetValue(tagName, out tag))
                {
                    if (!string.IsNullOrEmpty(tag.DefaultValue))
                    {
                        return(tag.DefaultValue);
                    }
                }
            }

            return(null);
        }
Пример #5
0
        public static string GetCategory(this TemplateInfo info, string defaultCategory)
        {
            ICacheTag tag = null;

            foreach (string tagName in TemplateCategoryTagNameProvider.CategoryTagNames)
            {
                if (info.Tags.TryGetValue(tagName, out tag))
                {
                    if (!string.IsNullOrEmpty(tag.DefaultValue))
                    {
                        return(tag.DefaultValue);
                    }
                }
            }

            return(defaultCategory);
        }
Пример #6
0
 public abstract int Expire(ICacheTag cacheTag);
 public static string GetTagKey(ICacheTag t)
 {
     return(string.Format(_tagKey, t));
 }
 bool IEquatable <ICacheTag> .Equals(ICacheTag other)
 {
     return(Equals((CacheTag)other));
 }