Output caching Support
Closed this issue · 2 comments
vipwan commented
//AddOutputCache
builder.Services.AddOutputCache(options =>
{
//options.AddBasePolicy(builder => builder.Expire(TimeSpan.FromSeconds(10)));
});
//UseOutputCache(); before MapBiwenQuickApis(); or app.MapGenQuickApis(app.Services);
app.UseOutputCache();
请注意: OutputCache只针对WebApi端的Response输出有效,如果把Api当Service使用 该特性自动无效 ,需要自行AOP支持
vipwan commented
现在 你可以使用特性或者HandlerBuilder 缓存输出了
// 使用builder.CacheOutput() 或者 [OutputCache]
[QuickApi("cache", Verbs = Verb.GET | Verb.POST)]
[QuickApiSummary("Cache缓存测试", "测试缓存功能")]
[OutputCache(Duration = 10)]
public class CachedApi : BaseQuickApiWithoutRequest<ContentResponse>
{
public override Task<ContentResponse> ExecuteAsync(EmptyRequest request)
{
return Task.FromResult(new ContentResponse(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")));
}
public override RouteHandlerBuilder HandlerBuilder(RouteHandlerBuilder builder)
{
//如果同时配置,那么[OutputCache]优先级别最高将覆盖CacheOutput()
//builder.CacheOutput(x =>
//{
// x.Expire(TimeSpan.FromSeconds(10));
//});
builder.WithTags("custom");
return base.HandlerBuilder(builder);
}
}
vipwan commented
请注意: OutputCache只针对WebApi端有效,如果把Api当Service使用 该特性自动无效 ,需要自行AOP支持