且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何保存在服务器上的用户凭据运行在后台查询

更新时间:2023-09-29 23:24:52

据我了解这一点,你需要运行每个用户的查询,但你不想使这个阻塞调用。你想要一个非规范化的读取模式,的UserData的响应。

As I understand this you will need to run a query per user but you do not want to make this a blocking call. You want the responsiveness of a denormalized read model, the UserData.

我有一个想法,你,而不是存储的凭据的地方,你只需启动一个线程,并提供线程从请求采取的当前凭据。

I have an idea where you instead of storing the credentials somewhere, you simply start a thread and provide that thread with the current credentials taken from the request.

class MyClass
{
    public static void DoSomething(object principal)
    {
        if (principal == null || !(principal is IPrincipal))
            throw new ArgumentException();
        Thread.CurrentPrincipal = (IPrincipal) principal;
        // Do heavy querying and update UserData
    }
}

我把这从ASP.NET MVC控制器是这样的:

I call this from an ASP.NET MVC Controller like this:

public ActionResult Index() 
{
    var t = new Thread(MyClass.DoSomething);
    t.Start(User);

    return View();
}

这将更新每个请求的UserData。如果你愿意,你可以介绍一些逻辑的更新频率,只让在一定条件下通话。

This would update the UserData for each request. If you want, you could introduce some logic for the update frequency and only make the call on certain conditions.

另一种方法我在想是对CQRS的心态,在那里我在这种情况下将发布包含序列化的IPrincipal 键,该消息会被消耗掉一个消息的步骤另一个实例/服务器,将更新的读出模式作为一个单独的过程。但我不确定,如果另一台服务器上反序列化的IPrincipal 将实际工作。

Another approach I was thinking about was a step towards the CQRS mindset, where I in this case would publish a message containing the serialized IPrincipal and that message would be consumed by another instance/server that would update the read model as a separate process. But I am uncertain that the IPrincipal would actually work if deserialized on another server.

反正我没有看到持续的凭据的利益。只是在一个新的线程或消耗的信息的上下文的范围内使用它们。

Anyway, I don't see the benefit of persisting the credentials. Just use them in the scope of a new thread or in the context of a message consumed.