public async Task NoLookupPolicy_DisablesLookup() { IOutputCachePolicy policy = NoLookupPolicy.Instance; var context = TestUtils.CreateUninitializedContext(); await policy.CacheRequestAsync(context, default); Assert.False(context.AllowCacheLookup); }
public async Task LockingPolicy_DisablesLocking() { IOutputCachePolicy policy = LockingPolicy.Disabled; var context = TestUtils.CreateUninitializedContext(); await policy.CacheRequestAsync(context, default); Assert.False(context.AllowLocking); }
public async Task DefaultCachePolicy_VariesByStar() { IOutputCachePolicy policy = DefaultPolicy.Instance; var context = TestUtils.CreateUninitializedContext(); await policy.CacheRequestAsync(context, default); Assert.Equal("*", context.CacheVaryByRules.QueryKeys); }
public async Task DefaultCachePolicy_AllowsLocking() { IOutputCachePolicy policy = DefaultPolicy.Instance; var context = TestUtils.CreateUninitializedContext(); await policy.CacheRequestAsync(context, default); Assert.True(context.AllowLocking); }
public async Task EnableCachePolicy_DisablesCache() { IOutputCachePolicy policy = EnableCachePolicy.Disabled; var context = TestUtils.CreateUninitializedContext(); context.EnableOutputCaching = true; await policy.CacheRequestAsync(context, default); Assert.False(context.EnableOutputCaching); }
/// <summary> /// Marks an endpoint to be cached with the specified policy. /// </summary> public static TBuilder CacheOutput <TBuilder>(this TBuilder builder, IOutputCachePolicy policy) where TBuilder : IEndpointConventionBuilder { ArgumentNullException.ThrowIfNull(builder); // Enable caching if this method is invoked on an endpoint, extra policies can disable it builder.Add(endpointBuilder => { endpointBuilder.Metadata.Add(policy); }); return(builder); }
/// <summary> /// Adds an <see cref="IOutputCachePolicy"/> instance to base policies. /// </summary> /// <param name="policy">The policy to add</param> public void AddBasePolicy(IOutputCachePolicy policy) { BasePolicies ??= new(); BasePolicies.Add(policy); }
/// <summary> /// Defines a <see cref="IOutputCachePolicy"/> which can be referenced by name. /// </summary> /// <param name="name">The name of the policy.</param> /// <param name="policy">The policy to add</param> public void AddPolicy(string name, IOutputCachePolicy policy) { NamedPolicies ??= new Dictionary <string, IOutputCachePolicy>(StringComparer.OrdinalIgnoreCase); NamedPolicies[name] = policy; }
/// <summary> /// Creates a new <see cref="PredicatePolicy"/> instance. /// </summary> /// <param name="asyncPredicate">The predicate.</param> /// <param name="policy">The policy.</param> public PredicatePolicy(Func <OutputCacheContext, ValueTask <bool> > asyncPredicate, IOutputCachePolicy policy) { _predicate = asyncPredicate; _policy = policy; }