Sharing MemoryCache ASP.NET in all applications

I read throughout the new MemoryCache class starting with the .Net Framework 4.0. From what I read, you can access MemoryCache in different .Net applications. I am trying to split an object between an Asp.Net application and a standard form window of a .Net application. If I add an object to MemoryCache in a .Net application, the Asp.Net application will not see it. Is there any way to do this? Thanks for your time, it is very much appreciated.

Windows Form Application:

Dim cache As ObjectCache = MemoryCache.Default Dim policy As New CacheItemPolicy() policy.AbsoluteExpiration = DateTimeOffset.Now.AddMinutes(60) cache.Set("testcache", TestObj, policy) 

Asp.Net Application:

  Dim cache As ObjectCache = MemoryCache.Default If IsNothing(cache("testcache")) Then Response.Write("TestCache Is Nothing") 

Thanks - Ryan

+4
source share
3 answers

MySQL memory tables work great and have stellar performance. 20/30 inserts the second and only about 1% of the processor load.

+1
source

No, It is Immpossible. MemoryCache not a distributed caching solution. Therefore, it will be available only locally.

If you are looking for an alternative with distributed cache, you can look at AppFabric or Redis .

However, it looks like an odd architecture that wants to share the cache. Perhaps exposing the level of shared services that both asp.net and winforms consume and have only services, the caching implementation will seem more logical (note that I actually know nothing about the problem you are trying to solve, so I could to be wrong).

Caching is often used for performance reasons, and not as a way to exchange data between applications.

+5
source

I understand that this advice is not timely, but for others reading this question, another possibility is Interprocess Communication (IPC) between the two programs. Thus, both programs can exchange messages / data directly, without going through an intermediate one.

https://msdn.microsoft.com/en-us/library/windows/desktop/aa365574(v=vs.85).aspx

The above documentation provides some of your options.

Clipboard COM Copy DDE data File mapping mail pipe slots RPC Windows sockets

In your case, mapped memory files may be the best approach, since it allows you to use shared memory space between applications. Essentially, your MySql / Redis approach is probably not that different.

0
source

All Articles