WCF:跨多个服务共享缓存数据 [英] WCF: sharing cached data across multiple services

查看:22
本文介绍了WCF:跨多个服务共享缓存数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在开发一个项目,该项目涉及大约 10 个不同的 WCF 服务,每个服务都有多个端点.其中一项服务将一些大数据表缓存在内存中.

We are developing a project that involves about 10 different WCF services with several endpoints each. One of the services keeps a few big tables of data cached in memory.

我们发现我们需要从其他服务访问该数据.我不想保留 2 个缓存副本,而是希望能够在所有服务之间共享这些表.

We have found we need access to that data from another service. Rather than keeping 2 copies of the cache, I'd like to be able to share those tables across all services.

我做了一些研究,发现了一些关于使用附加到服务主机的 IExtension 来存储共享数据的文章.

I have done some research and found some articles about using an IExtension attached to the servicehosts to store the shared data.

假设所有的服务都在同一个网站下运行,这会起作用吗?这是正确的方法吗?还是我应该去别处寻找?

Provided that all the services are running under the same web site, will that work? And is it the right approach? Or should I be looking elsewhere?

推荐答案

如果您缓存的数据被多个服务所需要,那么听起来 - 从面向服务的架构的角度来看 - 无论如何 - 它不会't 属于您调用它的任何一个服务.

If the data that you're caching is required by more than one service, it sounds like - from a Service Oriented Architecture perspective, anyway - that it doesn't belong in either of services you have calling it.

如果被缓存的数据与任何一个服务都没有真正相关,而是两个服务都需要的数据,那么它可能属于它自己的单独服务.您是否考虑过将缓存封装在第三个服务中,并执行服务到服务调用来检索您需要的数据?好处包括...

If the data being cached isn't really related to either service, but is something that both services need, then perhaps it belongs in it's own seperate service. Have you considered encapsulating your cache in a third service, and performing a service-to-service call to retrieve the data you need? Benefits include...

  1. 它解决了您最初的困境,避免了多次从数据库中读取整个缓存的需要;
  2. 它将缓存封装在一处,便于以后维护/更改.
  3. 它允许您通过放置另一个服务接口来将缓存的实现从其他服务中抽象出来.

总而言之,我建议这是最好的方法.唯一的缺点是进行服务到服务调用的额外开销,但这肯定比从数据库读取整个缓存要好.

All in all, I'd suggest that's the best approach. The only downside is the extra overhead of making the service-to-service call, but that surely outperforms having to read the whole cache from the database.

或者,如果您的缓存中的数据与调用缓存的两个服务都非常密切相关,即两个服务都添加/更改缓存中的数据等,那么也许应该将两个现有服务合并为单一服务.

Alternatively, if the data in your cache is very closely related to BOTH of the services that are calling the cache, i.e. both services add/change the data in the cache, etc. then perhaps the two existing services should be combined into a single service.

如果我说的有些道理,那么我所借鉴的 SOA 原则是 Service Autonomy.

If what I'm saying is making some sense, then then principle of SOA I'm drawing on is Service Autonomy.

这篇关于WCF:跨多个服务共享缓存数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆