/// <summary>
        /// Gets a trimmable view on the specified memoization <paramref name="cache"/>, exposing the memoized function's cache entry metrics.
        /// </summary>
        /// <param name="cache">The memoization cache to obtain a trimmable view for.</param>
        /// <returns>A trimmable view on the specified memoization <paramref name="cache"/> if the cache supports trimming; otherwise, null.</returns>
        public static ITrimmable <IMemoizationCacheEntryMetrics> AsTrimmableByMetrics(this IMemoizationCache cache)
        {
            if (cache == null)
            {
                throw new ArgumentNullException(nameof(cache));
            }

            return(cache.GetService <ITrimmable <IMemoizationCacheEntryMetrics> >());
        }
Example #2
0
 /// <summary>
 /// Creates a new memoized delegate representation.
 /// </summary>
 /// <param name="function">The memoized delegate.</param>
 /// <param name="cache">The memoization cache.</param>
 public MemoizedDelegate(TDelegate function, IMemoizationCache cache)
 {
     Delegate = function;
     Cache    = cache;
 }
        /// <summary>
        /// Gets a trimmable view on the specified memoization <paramref name="cache"/>, exposing the memoized function's pairs of arguments and results or errors.
        /// </summary>
        /// <typeparam name="T">The type of the memoized function's arguments.</typeparam>
        /// <typeparam name="TResult">The type of the memoized function's result.</typeparam>
        /// <param name="cache">The memoization cache to obtain a trimmable view for.</param>
        /// <returns>A trimmable view on the specified memoization <paramref name="cache"/> if the cache supports trimming; otherwise, null.</returns>
        public static ITrimmable <KeyValuePair <T, IValueOrError <TResult> > > AsTrimmableByArgumentAndResultOrError <T, TResult>(this IMemoizationCache <T, TResult> cache)
        {
            if (cache == null)
            {
                throw new ArgumentNullException(nameof(cache));
            }

            return(cache.GetService <ITrimmable <KeyValuePair <T, IValueOrError <TResult> > > >());
        }
 private static string GetOrAdd(IMemoizationCache <Obj, string> cache)
 {
     return(cache.GetOrAdd(new Obj()));
 }