示例#1
0
        public static ExpirationHint GetExpirationHint(Dependencies.CacheDependency dependency, DateTime absoluteExpiration, TimeSpan slidingExpiration)
        {
            ExpirationHint expirationHint = GetExpirationHint(absoluteExpiration, slidingExpiration);

            if (expirationHint == null)
            {
                return(GetExpirationHint(dependency));
            }
            ExpirationHint eh = GetExpirationHint(dependency);

            if (eh == null)
            {
                return(expirationHint);
            }
            AggregateExpirationHint hint3 = null;

            if (eh is AggregateExpirationHint)
            {
                hint3 = eh as AggregateExpirationHint;
                hint3.Add(expirationHint);
                return(hint3);
            }
            hint3 = new AggregateExpirationHint();
            hint3.Add(expirationHint);
            hint3.Add(eh);
            return(hint3);
        }
示例#2
0
 /// <summary>
 /// Reseta o hint.
 /// </summary>
 /// <param name="hint"></param>
 public void ResetVariant(ExpirationHint hint)
 {
     lock (this)
     {
         hint.ResetVariant(_context);
     }
 }
示例#3
0
        private static ExpirationHint GetExpirationHint(Dependencies.CacheDependency cacheDependency, AggregateExpirationHint aggregateHint)
        {
            if (cacheDependency == null)
            {
                return(null);
            }
            ExpirationHint expirationHint = null;

            if (cacheDependency is Dependencies.KeyDependency)
            {
                var dependency = cacheDependency as Dependencies.KeyDependency;
                expirationHint = new KeyDependency(dependency.CacheKeys, new DateTime(dependency.StartAfterTicks));
                aggregateHint.Add(expirationHint);
            }
            else if (cacheDependency is Dependencies.FileDependency)
            {
                var dependency2 = cacheDependency as Dependencies.FileDependency;
                expirationHint = new FileDependency(dependency2.fileNames, new DateTime(dependency2.StartAfterTicks));
                aggregateHint.Add(expirationHint);
            }
            if (aggregateHint.Hints.Length == 0)
            {
                return(null);
            }
            if (aggregateHint.Hints.Length == 1)
            {
                return(aggregateHint.Hints[0]);
            }
            return(aggregateHint);
        }
示例#4
0
 /// <summary>
 /// Reseta os dados do Hint.
 /// </summary>
 /// <param name="oldHint"></param>
 /// <param name="newHint"></param>
 public void ResetHint(ExpirationHint oldHint, ExpirationHint newHint)
 {
     lock (this)
     {
         if (newHint != null)
         {
             if (oldHint != null)
             {
                 ((IDisposable)oldHint).Dispose();
             }
             newHint.Reset(_context);
         }
     }
 }
示例#5
0
 public static Dependencies.CacheDependency GetCacheDependency(ExpirationHint hint, out DateTime absoluteExpiration, out TimeSpan slidingExpiration)
 {
     Dependencies.CacheDependency cacheDependency = null;
     absoluteExpiration = DateTime.MaxValue;
     slidingExpiration  = TimeSpan.Zero;
     if (hint != null)
     {
         if (hint is AggregateExpirationHint)
         {
             AggregateExpirationHint hint2 = (AggregateExpirationHint)hint;
             if ((hint2.Hints != null) && (hint2.Hints.Length > 0))
             {
                 foreach (ExpirationHint hint3 in hint2.Hints)
                 {
                     AddToDependency(ref cacheDependency, GetCacheDependency(hint3, out absoluteExpiration, out slidingExpiration));
                 }
             }
             return(cacheDependency);
         }
         if (hint is FixedExpiration)
         {
             absoluteExpiration = ((FixedExpiration)hint).AbsoluteTime;
             return(cacheDependency);
         }
         if (hint is IdleExpiration)
         {
             slidingExpiration = ((IdleExpiration)hint).SlidingTime;
             return(cacheDependency);
         }
         if (hint is KeyDependency)
         {
             var dependency2 = (KeyDependency)hint;
             AddToDependency(ref cacheDependency, new Dependencies.KeyDependency(dependency2.CacheKeys, new DateTime(dependency2.StartAfterTicks)));
             return(cacheDependency);
         }
         if (hint is FileDependency)
         {
             FileDependency dependency3 = (FileDependency)hint;
             AddToDependency(ref cacheDependency, new Dependencies.FileDependency(dependency3.FileNames, new DateTime(dependency3.StartAfterTicks)));
             return(cacheDependency);
         }
         return(cacheDependency);
     }
     return(cacheDependency);
 }
示例#6
0
 /// <summary>
 /// Salva a dia no escritor informado.
 /// </summary>
 /// <param name="writer"></param>
 /// <param name="expHint"></param>
 public static void WriteExpHint(CompactWriter writer, ExpirationHint expHint)
 {
     if (expHint == null)
     {
         writer.Write((short)(-1));
     }
     else
     {
         writer.Write((short)expHint.HintType);
         if (expHint.HintType == ExpirationHintType.ExtensibleDependency)
         {
             writer.WriteObject(expHint);
         }
         else
         {
             expHint.Serialize(writer);
         }
     }
 }
示例#7
0
 public void UpdateIndex(object key, ExpirationHint hint, bool hasDependentKeys)
 {
     if ((key != null) && (hint != null))
     {
         lock (_status_mutex)
         {
             if (!this.IsInProgress)
             {
                 if (!_mainIndex.Contains(key))
                 {
                     _mainIndex[key] = new ExpiryIndexEntry(hint, hasDependentKeys);
                 }
                 else
                 {
                     ExpiryIndexEntry entry = _mainIndex[key] as ExpiryIndexEntry;
                     if (entry != null)
                     {
                         entry.Hint             = hint;
                         entry.HasDependentKeys = hasDependentKeys;
                     }
                 }
             }
             else if (_transitoryIndex[key] == null)
             {
                 _transitoryIndex[key] = new ExpiryIndexEntry(hint, hasDependentKeys);
             }
             else
             {
                 ExpiryIndexEntry entry2 = _transitoryIndex[key] as ExpiryIndexEntry;
                 if (entry2 != null)
                 {
                     entry2.Hint             = hint;
                     entry2.HasDependentKeys = hasDependentKeys;
                 }
             }
         }
     }
 }
示例#8
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="hint"></param>
 /// <param name="hasDependentKeys"></param>
 public ExpiryIndexEntry(ExpirationHint hint, bool hasDependentKeys)
 {
     _hint             = hint;
     _hasDependentKeys = hasDependentKeys;
 }
示例#9
0
 /// <summary>
 /// Construtor padrão.
 /// </summary>
 /// <param name="hint"></param>
 public ExpiryIndexEntry(ExpirationHint hint) : this(hint, false)
 {
 }