Cache Block Application,在ASP.NET与Windows Service共享Cache.
问题:Cache Block Application,能否做到在ASP.NET,WinForm,Windows Service共享同一个缓存数据?
答案当然说行。也可以说不行。
大家都知道。Cache Block提供了了多种缓存方式。有内存,数据库,自定义。通过数据库的方式。我们可以做到共享一个缓存数据,自带的帮助文档也有提到如何共享缓存。但内存呢?在默认情况下。CBA(Cache Block Application)采用单件模式+HashTable方式来缓存数据。通过Timer事件来进行清理过期的数据和文件依赖。这里我也不讨论有关CBA的架构和实现原理了。还是回到原来的问题。能否共享?
我们可能想到的一个解决方法是,就这需要跨进程数据共享和交互了。确实这样。这个星期休息的时候仔细上网找了资料。
http://www.codeproject.com/dotnet/globalcache.asp
里面讲到了通过内存文件映射的方式共享缓存。
星期一同事推荐了一篇:
http://www.codeproject.com/aspnet/VbNetMemoryMappedCache.asp
里面也提到上面的那篇文章。并特意提到:
The sample code supplied by this article has one disadvantage though: if I hosted my cache in a Windows Service, I wasn't able to access it from within ASP.NET。
I've mentioned earlier that both of these solutions don't work if you want to access a cache created by a Windows Service from within ASP.NET. The problem is that both solutions create their Mutexes and the Memory Mapped Files using default security. More information about the meaning of default security and this problem can be found in the Mutex Madness-paragraph of Ask Dr. GUI #49: MSDN.
答案当然说行。也可以说不行。
大家都知道。Cache Block提供了了多种缓存方式。有内存,数据库,自定义。通过数据库的方式。我们可以做到共享一个缓存数据,自带的帮助文档也有提到如何共享缓存。但内存呢?在默认情况下。CBA(Cache Block Application)采用单件模式+HashTable方式来缓存数据。通过Timer事件来进行清理过期的数据和文件依赖。这里我也不讨论有关CBA的架构和实现原理了。还是回到原来的问题。能否共享?
我们可能想到的一个解决方法是,就这需要跨进程数据共享和交互了。确实这样。这个星期休息的时候仔细上网找了资料。
http://www.codeproject.com/dotnet/globalcache.asp
里面讲到了通过内存文件映射的方式共享缓存。
星期一同事推荐了一篇:
http://www.codeproject.com/aspnet/VbNetMemoryMappedCache.asp
里面也提到上面的那篇文章。并特意提到:
The sample code supplied by this article has one disadvantage though: if I hosted my cache in a Windows Service, I wasn't able to access it from within ASP.NET。
I've mentioned earlier that both of these solutions don't work if you want to access a cache created by a Windows Service from within ASP.NET. The problem is that both solutions create their Mutexes and the Memory Mapped Files using default security. More information about the meaning of default security and this problem can be found in the Mutex Madness-paragraph of Ask Dr. GUI #49: MSDN.
