コード例 #1
0
        /// <summary>
        /// Creates a memoization cache factory that keeps function memoization caches for each thread on which the memoized function gets invoked.
        /// This is useful to reduce cache access lock contention and can be used to make a memoization cache safe for concurrent access, at the expense of keeping a cache per thread.
        /// </summary>
        /// <param name="factory">The memoization cache factory to wrap with thread-local caching behavior.</param>
        /// <param name="exposeThreadLocalView">Indicates whether the caches returned from the resulting factory provide a thread-local view on the cache, for properties like Count and methods like Clear.</param>
        /// <returns>A memoization cache factory that wraps the specified <paramref name="factory"/> and adds thread-local isolation to it.</returns>
        public static IWeakMemoizationCacheFactory WithThreadLocal(this IWeakMemoizationCacheFactory factory, bool exposeThreadLocalView)
        {
            if (factory == null)
            {
                throw new ArgumentNullException(nameof(factory));
            }

            return(new ThreadLocalFactory(factory, exposeThreadLocalView));
        }
コード例 #2
0
ファイル: Memoizer.cs プロジェクト: tamirdresher/reaqtor
        /// <summary>
        /// Creates a function memoizer that uses the specified <paramref name="factory"/> to create memoization caches that don't keep the function arguments alive.
        /// </summary>
        /// <param name="factory">Memoization cache factory to use when memoizing functions using the resulting memoizer.</param>
        /// <returns>Function memoizer to speed up function invocations by caching their result as long as the memoized function arguments are alive.</returns>
        public static IWeakMemoizer CreateWeak(IWeakMemoizationCacheFactory factory)
        {
            if (factory == null)
            {
                throw new ArgumentNullException(nameof(factory));
            }

            return(new WeakImpl(factory));
        }
コード例 #3
0
 public ThreadLocalFactory(IWeakMemoizationCacheFactory factory, bool exposeThreadLocalView)
 {
     _factory          = factory;
     _exposeGlobalView = !exposeThreadLocalView;
 }
コード例 #4
0
 public ThreadLocalFactory(IWeakMemoizationCacheFactory factory) => _factory = factory;
コード例 #5
0
ファイル: Memoizer.cs プロジェクト: tamirdresher/reaqtor
 public WeakImpl(IWeakMemoizationCacheFactory factory) => _factory = factory;