如何在 WCF 服务和托管该服务的进程之间共享缓存数据?
我有一个普通的 Windows 服务,可以处理大型数据集并将其存储到数据库中。此 Windows 服务还充当托管 WCF 服务,该服务为一个或多个 GUI 提供处理后的数据。
目前,WCF 服务必须至少访问数据库一次才能为客户端获取数据,但数据集的大小使得速度非常慢,并且由于数据重复而占用大量内存。理想情况下,我想与 WCF 服务直接(在内存中)共享数据处理的结果。有办法做到这一点吗?
I have an ordinary windows service that processes a large data set and stores it to a DB. This windows service also acts to host a WCF service that serves the processed data up to one or more GUIs.
Currently the WCF service has to hit the DB at least once to get the data for the client, but the size of the data set is such that this is extremely slow, and eats up a lot of memory because of the duplication of data. Ideally I would like to share the results of the data processing directly (in memory) with the WCF service. Is there a way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是的,使用分布式缓存引擎。
基本上,分布式缓存引擎是在一台或多台计算机上运行的独立进程,用于管理缓存。此缓存站点位于其自己的进程中,通常缓存引擎提供用于访问该数据的 API
主要选项是
Yes, using a distributed cache engine.
Basically, the distributed cache engine is a separate process running on one or more machines, that manages a cache. This cache sites in it's own process, and typically the cache engine provides an API for accessing that data
The main options are
实际上,我的一位同事发现可以通过静态方法从主机访问 WCF 服务,甚至不需要将该服务设置为单例模式。
然后,您可以从主机进程执行此操作来调用该方法:
我不确定这是否被认为是不好的做法,或者它是否会导致我们没有考虑到的任何问题,但它似乎对我有用:)
Actually, a colleague of mine found it is possible to access the WCF Service from the host via static methods, and you don't even need to have the service in singleton mode.
From the host process you can then do this to call the method:
I'm not sure if this is considered bad practice, or if it will cause any problems we haven't considered, but it seems to be working for me :)
是的。您需要以单例模式。请参阅此相关问题。
Yes. You'll need to create your WCF host in singleton mode. See this related question.