-
Notifications
You must be signed in to change notification settings - Fork 9.9k
/
CacheTagHelperMemoryCacheFactory.cs
38 lines (33 loc) · 1.26 KB
/
CacheTagHelperMemoryCacheFactory.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Options;
namespace Microsoft.AspNetCore.Mvc.TagHelpers;
/// <summary>
/// A factory for <see cref="IMemoryCache"/>s configured using <see cref="CacheTagHelperOptions"/>.
/// <see cref="CacheTagHelper"/> uses this factory to set its <see cref="CacheTagHelper.MemoryCache"/>.
/// </summary>
public class CacheTagHelperMemoryCacheFactory
{
/// <summary>
/// Creates a new <see cref="CacheTagHelperMemoryCacheFactory"/>.
/// </summary>
/// <param name="options">The <see cref="CacheTagHelperOptions"/> to apply to the <see cref="Cache"/>.</param>
public CacheTagHelperMemoryCacheFactory(IOptions<CacheTagHelperOptions> options)
{
Cache = new MemoryCache(new MemoryCacheOptions
{
SizeLimit = options.Value.SizeLimit,
TrackLinkedCacheEntries = true,
});
}
// For testing only.
internal CacheTagHelperMemoryCacheFactory(IMemoryCache cache)
{
Cache = cache;
}
/// <summary>
/// Gets the <see cref="IMemoryCache"/>.
/// </summary>
public IMemoryCache Cache { get; }
}