[英]ASP.NET MemoryCache Sharing Across Applications
I have been reading all over the place about the new MemoryCache class starting in .Net Framework 4.0. 我一直在各处阅读有关从.Net Framework 4.0开始的新MemoryCache类的信息。 From what I've read, you can access the MemoryCache across different .Net applications.
通过阅读,您可以跨不同的.Net应用程序访问MemoryCache。 I am trying to share an object between an Asp.Net application and a standard windows forms .Net application.
我正在尝试在Asp.Net应用程序和标准Windows窗体.Net应用程序之间共享一个对象。 If I add the object to the MemoryCache in the .Net application, the Asp.Net application does not see it.
如果将对象添加到.Net应用程序中的MemoryCache,则Asp.Net应用程序看不到它。 Is there any way to accomplish this?
有什么办法可以做到这一点? Thank you for your time, it is greatly appreciated.
谢谢您的宝贵时间,不胜感激。
Windows Form App: Windows Form应用程序:
Dim cache As ObjectCache = MemoryCache.Default
Dim policy As New CacheItemPolicy()
policy.AbsoluteExpiration = DateTimeOffset.Now.AddMinutes(60)
cache.Set("testcache", TestObj, policy)
Asp.Net App: Asp.Net应用程序:
Dim cache As ObjectCache = MemoryCache.Default
If IsNothing(cache("testcache")) Then Response.Write("TestCache Is Nothing")
Thanks - Ryan 谢谢-瑞安
No, that's not possible. 不,那不可能。
MemoryCache
is not a distributed caching solution. MemoryCache
不是分布式缓存解决方案。 So it will only be available locally. 因此它将仅在本地可用。
If you are looking for a distributed cache alternative you may want to look into AppFabric or Redis . 如果您正在寻找分布式缓存替代方案,则可能需要研究AppFabric或Redis 。
However, it does sound a bit like an odd architecture to want to share the cache that way. 但是,以这种方式共享缓存听起来确实有点奇怪。 Maybe exposing a shared services layer, that both the asp.net and winforms consume, and have just the services implement the caching would seem more logical (take into account I actually know nothing about the problem you are trying to solve, so I could be wrong).
也许暴露了一个共享服务层,即asp.net和winforms都消耗了,而仅由服务实现了缓存,这似乎更合乎逻辑(考虑到我实际上对您要解决的问题一无所知,所以我可以错误)。
Caching is more commonly used for performance reasons, not as a way to share data among applications. 出于性能原因,更常使用缓存,而不是将其作为在应用程序之间共享数据的一种方式。
MySQL memory tables are working great and having stellar performance. MySQL内存表运行良好,并且具有出色的性能。 20/30 inserts a second and only around 1% CPU load.
20/30插入一秒钟,而CPU负载仅为1%左右。
I realize this advice is not timely, but for others reading this question, another possibility is Interprocess Communication (IPC) between the two programs. 我意识到此建议并不及时,但是对于其他阅读此问题的人来说,另一个可能是两个程序之间的进程间通信(IPC)。 This way the two programs can exchange messages/data directly without going thru an intermediate.
这样,两个程序就可以直接交换消息/数据,而无需经过中间程序。
https://msdn.microsoft.com/en-us/library/windows/desktop/aa365574(v=vs.85).aspx https://msdn.microsoft.com/zh-CN/library/windows/desktop/aa365574(v=vs.85).aspx
From the documentation above, here are some of your options. 根据上面的文档,这是您的一些选择。
Clipboard COM Data Copy DDE File Mapping Mailslots Pipes RPC Windows Sockets 剪贴板COM数据复制DDE文件映射Mailslots管道RPC Windows套接字
In your case, mapped memory files might be the best approach as it allows for a shared memory space between applications. 在您的情况下,映射内存文件可能是最好的方法,因为它允许应用程序之间共享内存空间。 Fundamentally, your MySql/Redis approach is probably not that different.
从根本上讲,您的MySql / Redis方法可能没有什么不同。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.