问题
I need caching facility which should work from both WCF and from within an ASP .NET app. I have seen:
System.Web.Caching.Cachewhich is not usable from WCF (as I understand it is usable only if service is hosted in IIS, which is not always the case)System.Runtime.Cachingwhich is usable from both of them, but only available from .NET 4, but our .NET version is 3.5.
Any suggestions?
回答1:
You can absolutely use System.Web.Caching.Cache outside of IIS. Just add a reference to System.Web and away you go - it is absolutely not a feature of IIS.
There were issues in .NET 1.0 and 1.1 but apparently not in 2.0 and upwards - see this Knowledge Base article.
But like Davide Piras I would also recommend considering AppFabric to share the cache between your two applications, if that would be useful. I'm not sure what you mean by "my requirement cannot afford something like AppFabric" - by "afford" are you talking about performance, memory, or what? Whilst AppFabric is designed to be used on a cache server it does not by any means require dedicated hardware, you can run the service on the same box as your application if you need to.
回答2:
new solution use Windows Server AppFabric Caching
http://cgeers.com/2010/07/04/windows-server-appfabric-caching/
http://dotnet.dzone.com/articles/caching-wcf-services-part-2
http://channel9.msdn.com/Events/TechEd/NorthAmerica/2012/AAP314
***2.in .NET 1.0 and 1.1 http://support.microsoft.com/kb/917411
来源:https://stackoverflow.com/questions/11686728/caching-usable-in-both-wcf-and-asp-net-applications-net-3-5