Esempio n. 1
0
        /// <summary>
        /// Specifies that each entry should be automatically removed from the cache once a duration
        /// has elapsed after the entry's creation, the most recent replacement of its value, or its
        /// last read. The expiration time is reset by all cache read and write operations (including
        /// <see cref="ICache{K, V}.TryGetValue(K)"/> and <see cref="ICache{K, V}.Add(K, V)"/>.
        ///
        /// Expired entries may be counted in <see cref="ICache{K, V}.EstimatedSize"/>, but will never be
        /// visible to read or write operations. Expired entries are cleaned up as part of the routine
        /// maintenance.
        /// </summary>
        /// <param name="expiry">The expiry to use in calculating the expiration time of cache entries</param>
        /// <returns></returns>
        /// <exception cref="InvalidOperationException">if expiration was already set.</exception>
        /// <exception cref="ArgumentNullException">if expiry is <see langword="null"/></exception>
        public Caffeine <K, V> SpecifyExpireVariable(IExpiry <K, V> expiry)
        {
            if (expireAfterAccessNanoseconds != UNSET_INT)
            {
                throw new InvalidOperationException("Expirer may not be used with ExpireAfterAccess.");
            }

            if (expireAfterWriteNanoseconds != UNSET_INT)
            {
                throw new InvalidOperationException("Expirer may not be used with ExpireAfterWrite.");
            }

            if (this.expiry != null)
            {
                throw new InvalidOperationException("Expirer was already set.");
            }

            if (expiry == null)
            {
                throw new ArgumentNullException("expiry", "Expirer cannot be set to NULL.");
            }


            this.expiry = expiry;
            return(this);
        }
Esempio n. 2
0
 public AsyncExpiry(IExpiry <K, V> @delegate)
 {
     this.@delegate = @delegate ?? throw new ArgumentNullException("@delegate", "expiry cannot be NULL.");
 }