Ejemplo n.º 1
0
        /// <summary>
        /// Notify the metric reporter that the cache size has changed.
        /// </summary>
        /// <param name="name">
        /// The cache name. This cannot be null, empty or whitespace.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="name"/> cannot be null, empty or whitespace.
        /// </exception>
        public override void NotifySizeChange(string name)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentNullException(nameof(name));
            }

            UpdateSizeCounter(name, SizeCallbacks[name]());
        }
        /// <summary>
        /// Remove the size callback added through <see cref="AddSizeCallback"/>.
        /// Do nothing if there is no callback for <paramref name="name"/>.
        /// </summary>
        /// <param name="name">
        /// The cache name. This cannot be null, empty or whitespace.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="name"/> cannot be null, empty or whitespace.
        /// </exception>
        public void RemoveSizeCallback(string name)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentNullException(nameof(name));
            }

            Func <long> oldGetSize;

            SizeCallbacks.TryRemove(name, out oldGetSize);
        }
        /// <summary>
        /// Add a callback to get the named cache's current size.
        /// </summary>
        /// <param name="name">
        /// The cache name. This cannot be null, empty or whitespace.
        /// </param>
        /// <param name="getSize">
        /// A function that returns the cache size. This cannot be null.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="name"/> cannot be null, empty or whitespace.
        /// <paramref name="getSize"/> cannot be null.
        /// </exception>
        public void AddSizeCallback(string name, Func <long> getSize)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentNullException(nameof(name));
            }
            if (getSize == null)
            {
                throw new ArgumentNullException(nameof(getSize));
            }

            SizeCallbacks.AddOrUpdate(name, n => getSize, (n, gs) => getSize);
            ZeroSizeCounter(name);
        }
 /// <summary>
 /// Dispose
 /// </summary>
 public virtual void Dispose()
 {
     CleanUpCounters();
     SizeCallbacks.Clear();
     HitsAndMissesCallbacks.Clear();
 }