/// <summary> /// Creates a memoization cache for the specified <paramref name="function"/> that doesn't keep cache entry keys alive. /// </summary> /// <typeparam name="T">Type of the memoization cache entry keys. This type has to be a reference type.</typeparam> /// <typeparam name="R">Type of the memoization cache entry values.</typeparam> /// <param name="function">The function to memoize.</param> /// <param name="options">Flags to influence the memoization behavior.</param> /// <returns>An empty memoization cache instance.</returns> public IMemoizationCache <T, R> Create <T, R>(Func <T, R> function, MemoizationOptions options) where T : class { if (function == null) { throw new ArgumentNullException(nameof(function)); } return(new MemoizationCacheFactory.NopImpl.Cache <T, R>(function)); }
/// <summary> /// Creates a memoization cache for the specified <paramref name="function"/> that doesn't keep cache entry keys alive. /// </summary> /// <typeparam name="T">Type of the memoization cache entry keys. This type has to be a reference type.</typeparam> /// <typeparam name="R">Type of the memoization cache entry values.</typeparam> /// <param name="function">The function to memoize.</param> /// <param name="options">Flags to influence the memoization behavior.</param> /// <returns>An empty memoization cache instance.</returns> public IMemoizationCache <T, R> Create <T, R>(Func <T, R> function, MemoizationOptions options) where T : class { if (function == null) { throw new ArgumentNullException(nameof(function)); } var cacheError = (options & MemoizationOptions.CacheException) > MemoizationOptions.None; return(new Cache <T, R>(function, _ranker, _maxCapacity, _descending, _ageThreshold, cacheError, _stopwatchFactory)); }
/// <summary> /// Creates a memoization cache for the specified <paramref name="function"/> that doesn't keep cache entry keys alive. /// </summary> /// <typeparam name="T">Type of the memoization cache entry keys. This type has to be a reference type.</typeparam> /// <typeparam name="R">Type of the memoization cache entry values.</typeparam> /// <param name="function">The function to memoize.</param> /// <param name="options">Flags to influence the memoization behavior.</param> /// <returns>An empty memoization cache instance.</returns> public IMemoizationCache <T, R> Create <T, R>(Func <T, R> function, MemoizationOptions options) where T : class { if (function == null) { throw new ArgumentNullException(nameof(function)); } var cacheError = (options & MemoizationOptions.CacheException) > MemoizationOptions.None; return(new Cache <T, R>(function, _maxCapacity, cacheError)); }
public IMemoizationCache <T, R> Create <T, R>(Func <T, R> function, MemoizationOptions options) where T : class { if (function == null) { throw new ArgumentNullException(nameof(function)); } if (_exposeGlobalView) { return(new MemoizationCacheFactoryExtensions.ThreadLocalFactory.ImplUnion <T, R>(() => _factory.Create(function, options))); } return(new MemoizationCacheFactoryExtensions.ThreadLocalFactory.Impl <T, R>(() => _factory.Create(function, options))); }
public IMemoizationCache <T, R> Create <T, R>(Func <T, R> function, MemoizationOptions options, IEqualityComparer <T> comparer) { if (function == null) { throw new ArgumentNullException(nameof(function)); } if (_exposeGlobalView) { return(new ImplUnion <T, R>(() => _factory.Create(function, options, comparer))); } return(new Impl <T, R>(() => _factory.Create(function, options, comparer))); }
/// <summary> /// Creates a memoization cache for the specified <paramref name="function"/> that doesn't keep cache entry keys alive. /// </summary> /// <typeparam name="T">Type of the memoization cache entry keys. This type has to be a reference type.</typeparam> /// <typeparam name="R">Type of the memoization cache entry values.</typeparam> /// <param name="function">The function to memoize.</param> /// <param name="options">Flags to influence the memoization behavior.</param> /// <returns>An empty memoization cache instance.</returns> public IMemoizationCache <T, R> Create <T, R>(Func <T, R> function, MemoizationOptions options) where T : class { if (function == null) { throw new ArgumentNullException(nameof(function)); } if ((options & MemoizationOptions.CacheException) > MemoizationOptions.None) { return(new CacheWithException <T, R>(function)); } else { return(new Cache <T, R>(function)); } }
/// <summary> /// Memoizes the specified <paramref name="function"/>. /// </summary> /// <typeparam name="T">Type of the function argument.</typeparam> /// <typeparam name="TResult">Type of the function result.</typeparam> /// <param name="function">The function to memoize.</param> /// <param name="options">Flags to influence the memoization behavior.</param> /// <param name="comparer">Comparer to compare the function argument during lookup in the memoization cache.</param> /// <returns>A memoized delegate containing the memoized function and providing access to the memoization cache.</returns> public IMemoizedDelegate <Func <T, TResult> > Memoize <T, TResult>(Func <T, TResult> function, MemoizationOptions options = MemoizationOptions.None, IEqualityComparer <T> comparer = null) { if (function == null) { throw new ArgumentNullException(nameof(function)); } var cache = _factory.Create(function, options, comparer); return(new MemoizedDelegate <Func <T, TResult> >(cache.GetOrAdd, cache)); }
public IMemoizationCache <T, TResult> Create <T, TResult>(Func <T, TResult> function, MemoizationOptions options) where T : class { return(new MyCache <T, TResult>()); }
public IMemoizationCache <T, TResult> Create <T, TResult>(Func <T, TResult> function, MemoizationOptions options, IEqualityComparer <T> comparer) { return(new MyCache <T, TResult>()); }
/// <summary> /// Creates a memoization cache for the specified <paramref name="function"/> using the specified <paramref name="comparer"/> to compare cache entries. /// </summary> /// <typeparam name="T">Type of the memoization cache entry keys.</typeparam> /// <typeparam name="TResult">Type of the memoization cache entry values.</typeparam> /// <param name="function">The function to memoize.</param> /// <param name="options">Flags to influence the memoization behavior.</param> /// <param name="comparer">Comparer to compare the key during lookup in the memoization cache.</param> /// <returns>An empty memoization cache instance.</returns> public IMemoizationCache <T, TResult> Create <T, TResult>(Func <T, TResult> function, MemoizationOptions options, IEqualityComparer <T> comparer) { if (function == null) { throw new ArgumentNullException(nameof(function)); } if ((options & MemoizationOptions.CacheException) > MemoizationOptions.None) { return(new CacheWithException <T, TResult>(function, comparer)); } else { return(new Cache <T, TResult>(function, comparer)); } }
/// <summary> /// Memoizes the specified <paramref name="function"/> using the specified <paramref name="memoizer"/>. /// </summary> /// <typeparam name="TResult">Type of the function result.</typeparam> /// <param name="memoizer">The memoizer used to memoize the function.</param> /// <param name="function">The function to memoize.</param> /// <param name="options">Flags to influence the memoization behavior.</param> /// <returns>A memoized delegate containing the memoized function and providing access to the memoization cache.</returns> public static IMemoizedDelegate <Func <TResult> > MemoizeWeak <TResult>(this IWeakMemoizer memoizer, Func <TResult> function, MemoizationOptions options = MemoizationOptions.None) { if (memoizer == null) { throw new ArgumentNullException(nameof(memoizer)); } if (function == null) { throw new ArgumentNullException(nameof(function)); } var res = memoizer.MemoizeWeak <object, TResult>(_ => function(), options); var del = res.Delegate; return(new MemoizedDelegate <Func <TResult> >(() => del(null), res.Cache)); }
/// <summary> /// Memoizes the specified <paramref name="function"/>. /// </summary> /// <typeparam name="TResult">Type of the function result.</typeparam> /// <param name="function">The function to memoize.</param> /// <param name="options">Flags to influence the memoization behavior.</param> /// <returns>A memoized delegate containing the memoized function and providing access to the memoization cache.</returns> public static IMemoizedDelegate <Func <TResult> > Memoize <TResult>(this Func <TResult> function, MemoizationOptions options = MemoizationOptions.None) { if (function == null) { throw new ArgumentNullException(nameof(function)); } if ((options & MemoizationOptions.CacheException) > MemoizationOptions.None) { return(MemoizeWithError(function)); } else { return(MemoizeWithoutError(function)); } }
/// <summary> /// Memoizes the specified <paramref name="function"/> using the specified <paramref name="memoizer"/>. /// </summary> /// <typeparam name="T">Type of the function argument.</typeparam> /// <typeparam name="TResult">Type of the function result.</typeparam> /// <param name="memoizer">The memoizer used to memoize the function.</param> /// <param name="function">The function to memoize.</param> /// <param name="options">Flags to influence the memoization behavior.</param> /// <returns>A memoized delegate containing the memoized function and providing access to the memoization cache.</returns> public static IMemoizedDelegate <Func <T, TResult> > Memoize <T, TResult>(this IMemoizer memoizer, Func <T, TResult> function, MemoizationOptions options = MemoizationOptions.None) { if (memoizer == null) { throw new ArgumentNullException(nameof(memoizer)); } if (function == null) { throw new ArgumentNullException(nameof(function)); } return(memoizer.Memoize <T, TResult>(function, options, comparer: null)); }
/// <summary> /// Creates a memoization cache for the specified <paramref name="function"/> using the specified <paramref name="comparer"/> to compare cache entries. /// </summary> /// <typeparam name="T">Type of the memoization cache entry keys.</typeparam> /// <typeparam name="TResult">Type of the memoization cache entry values.</typeparam> /// <param name="function">The function to memoize.</param> /// <param name="options">Flags to influence the memoization behavior.</param> /// <param name="comparer">Comparer to compare the key during lookup in the memoization cache.</param> /// <returns>An empty memoization cache instance.</returns> public IMemoizationCache <T, TResult> Create <T, TResult>(Func <T, TResult> function, MemoizationOptions options, IEqualityComparer <T> comparer) { if (function == null) { throw new ArgumentNullException(nameof(function)); } var cacheError = (options & MemoizationOptions.CacheException) > MemoizationOptions.None; return(new Cache <T, TResult>(function, _maxCapacity, comparer, cacheError)); }
/// <summary> /// Creates a memoization cache for the specified <paramref name="function"/> using the specified <paramref name="comparer"/> to compare cache entries. /// </summary> /// <typeparam name="T">Type of the memoization cache entry keys.</typeparam> /// <typeparam name="TResult">Type of the memoization cache entry values.</typeparam> /// <param name="function">The function to memoize.</param> /// <param name="options">Flags to influence the memoization behavior.</param> /// <param name="comparer">Comparer to compare the key during lookup in the memoization cache.</param> /// <returns>An empty memoization cache instance.</returns> public IMemoizationCache <T, TResult> Create <T, TResult>(Func <T, TResult> function, MemoizationOptions options, IEqualityComparer <T> comparer) { if (function == null) { throw new ArgumentNullException(nameof(function)); } return(new Cache <T, TResult>(function)); }
/// <summary> /// Creates a memoization cache for the specified <paramref name="function"/> that doesn't keep cache entry keys alive. /// </summary> /// <typeparam name="T">Type of the memoization cache entry keys.</typeparam> /// <typeparam name="TResult">Type of the memoization cache entry values.</typeparam> /// <param name="function">The function to memoize.</param> /// <param name="options">Flags to influence the memoization behavior.</param> /// <param name="comparer">Comparer to compare the key during lookup in the memoization cache.</param> /// <returns>An empty memoization cache instance.</returns> public IMemoizationCache <T, TResult> Create <T, TResult>(Func <T, TResult> function, MemoizationOptions options, IEqualityComparer <T> comparer) { if (function == null) { throw new ArgumentNullException(nameof(function)); } var cacheError = (options & MemoizationOptions.CacheException) > MemoizationOptions.None; return(new Cache <T, TResult>(function, _ranker, _maxCapacity, _descending, _ageThreshold, comparer, cacheError, _stopwatchFactory)); }