使用Servicestack,当对ServiceSource使用AutoQuery时,如何缓存结果集?

使用Servicestack,当对ServiceSource使用AutoQuery时,如何缓存结果集?,
Warning: implode(): Invalid arguments passed in /data/phpspider/zhask/webroot/tpl/detail.html on line 45
,,我试图将ServiceStack的AutoQuery与服务源一起使用,但我要么无法使缓存正常工作,要么误解了它的工作原理 我试图实现的是向“边缘”微服务添加查询功能,该微服务调用提供完整数据列表的内部服务 重现我的问题的最少代码: 类程序 { 静态异步任务主(字符串[]args) { IWebHost主机=新WebHostBuilder() .UseKestrel((builderContext,options)=>options.Configure(builderContext.Configu

我试图将ServiceStack的AutoQuery与服务源一起使用,但我要么无法使缓存正常工作,要么误解了它的工作原理

我试图实现的是向“边缘”微服务添加查询功能,该微服务调用提供完整数据列表的内部服务

重现我的问题的最少代码:

类程序
{
静态异步任务主(字符串[]args)
{
IWebHost主机=新WebHostBuilder()
.UseKestrel((builderContext,options)=>options.Configure(builderContext.Configuration.GetSection(“Kestrel”))
.UseStartup()
.Build();
等待host.RunAsync();
}
}
公营创业
{
public void配置服务(IServiceCollection服务){}
公共无效配置(IApplicationBuilder应用程序,IHostingEnvironment环境)
{
app.UseServiceStack(新的AppHost());
运行(上下文=>Task.FromResult(0));
}
}
公共类AppHost:AppHostBase
{
public AppHost():base(“helloweb服务”,typeof(HelloService.Assembly){}
公共覆盖无效配置(Funq.Container)
{
container.AddSingleton();//否则HostContext.Cache为空
Add(新的AutoQueryDataFeature{MaxLimit=3,IncludeTotal=true}.AddDataSource(ctx=>ctx.ServiceSource(new Hello(),HostContext.Cache,TimeSpan.FromMinutes(5)));
}
}
//请求DTO
[路线(“/你好”)]
[路由(“/hello/{Name}”)]
公共类你好:QueryData
{
[QueryDataField(Condition=“StartsWith”,Field=nameof(Name))]
公共字符串名称{get;set;}
}
公共类命名为
{
公共字符串名称{get;set;}
}
公共类HelloService:服务
{
公共IAutoQueryData自动查询{get;set;}
公共异步任务任意(Hello查询)
{
//想象一下我正在打一个服务电话给另一个微服务公司。。。
var data=new List{new NameDto{Name=“Bob”},new NameDto{Name=“George”},new NameDto{Name=“Baldrick”},new NameDto{Name=“Nursey”},new NameDto{Name=“Melchett”},new NameDto{Name=“Kate”};
DataQuery DataQuery=AutoQuery.CreateQuery(查询、请求、新内存数据源(数据、查询、请求));
返回AutoQuery.Execute(查询、数据查询);
}
}   
Nuget软件包:Mircosoft.AspNetCore.All(2.2.1)和ServiceStack(5.4.0)

因此,在控制台(.NET Core 2.2)中,上述代码将在端口5000上启动并侦听

如果我进行查询,我将得到我的列表,该列表仅限于预期的结果数,并且我还可以按预期跳过/获取

但是,每次调用服务方法时,结果都不会被缓存(这是在我注册插件缓存5分钟时指定的),如果我在服务方法中放置断点,则每次都会重新创建“名称”列表。即使我向服务发出相同的请求,也会发生这种情况

我希望能够缓存结果集(在内存中是可以的),并且只在缓存过期时点击服务方法。我在这里做错了什么(或误解了什么)

编辑

我用来尝试Mythz建议的代码。。。现在我根本没有任何自动查询功能

类程序
{
静态异步任务主(字符串[]args)
{
IWebHost主机=新WebHostBuilder()
.UseKestrel((builderContext,options)=>options.Configure(builderContext.Configuration.GetSection(“Kestrel”))
.UseStartup()
.Build();
等待host.RunAsync();
}
}
公营创业
{
public void配置服务(IServiceCollection服务)
{
}
公共无效配置(IApplicationBuilder应用程序,IHostingEnvironment环境)
{
app.UseServiceStack(新的AppHost());
运行(上下文=>Task.FromResult(0));
}
}
公共类AppHost:AppHostBase
{
public AppHost():base(“helloweb服务”,typeof(HelloService.Assembly){}
公共覆盖无效配置(Funq.Container)
{
container.AddSingleton();
Add(新的AutoQueryDataFeature{MaxLimit=5}
.AddDataSource(ctx=>ctx.ServiceSource(ctx.Dto.ConvertTo()),
HostContext.Cache,TimeSpan.frommins(5));
}
}
公共类QueryGithubRepo:QueryData
{
公共字符串用户{get;set;}
公共字符串组织{get;set;}
}
公共类回购协议
{
公共int Id{get;set;}
公共字符串名称{get;set;}
公共字符串说明{get;set;}
公共字符串主页{get;set;}
公共整数监视程序\u Count{get;set;}
公共int星探计数{get;set;}
公共整数大小{get;set;}
公共字符串全名{get;set;}
在{get;set;}处创建的公共日期时间
公共日期时间?在{get;set;}更新
公共bool有{get;set;}
公共布尔分叉{get;set;}
公共字符串Url{get;set;}//https://api.github.com/repos/NetCoreWebApps/bare
公共字符串Html_Url{get;set;}
公共布尔私有{get;set;}
public GithubRepo Parent{get;set;}//仅在单个结果上,例如:/repos/NetCoreWebApps/bare
}
公共类命名为
{
公共字符串名称{get;set;}
}
公共类HelloService:服务
{    
公共对象Get(QueryGithubRepo请求)
{
if(request.User==null&&request.Organization==null)
抛出新的ArgumentNullException(“用户”);
var url=request.User!=null
? $"https://api.github.com/users/{request.User}/repos“
: $"https://api.github.com/orgs/{请求组织}/repos”;
返回url.GetJsonFromUrl(requestFilter:req=>req.UserAgent=GetType().Name)
.FromJson();
}
}

如果您在服务实现中使用AutoQuery,则它只是一个查询正常结果的非a
public class QueryGithubRepo : QueryData<GithubRepo> 
{
    public string User { get; set; }
    public string Organization { get; set; }
}

public object Get(GetGithubRepos request)
{
    if (request.User == null && request.Organization == null)
        throw new ArgumentNullException("User");

    var url = request.User != null
        ? $"https://api.github.com/users/{request.User}/repos"
        : $"https://api.github.com/orgs/{request.Organization}/repos";

    return url.GetJsonFromUrl(requestFilter:req => req.UserAgent = GetType().Name)
        .FromJson<List<GithubRepo>>();
}
Plugins.Add(new AutoQueryDataFeature { MaxLimit = 100 }
    .AddDataSource(ctx => ctx.ServiceSource<GithubRepo>(ctx.Dto.ConvertTo<GetGithubRepos>(), 
        HostContext.Cache, TimeSpan.FromMinutes(5)));
);