How do I cache values in .NET 4 so that they are available across multiple applications?
I have created a website in Visual Studio 2010 (File -> New Web Site),开发者_开发百科 and to the resulting solution file I have added two more web sites. I know that for any one of the web sites I can use context.Application to share values among multiple users. But is there a way to share values among users of the different web sites?
In other words, is there a "solution level" cache object of some kind in .NET? I have not managed to find any answer through search engines.
Thanks in advance for your help
When I need to share data between Webware, I prefer to develop a WCF service and provide those data via a Singleton service.
Then, each client can get same data from the Singleton service.
Do you not have a database available on the backend? If you do, save/read your data to the DB. I don't know if you have any race conditions or not but this would be your main approach.
If you don't have a DB, your next choice may be reading/writing to disk. This presumes the apps are all hosted on the same server and have read/write access to a particular directory.
My last choice would be look for some other intra-application (but same IIS) approach, though it sounds like this is what you're after.
There's not such option. The best available option would be a permanent data store (XML, database...).
Although ASP.NET support such a thing for sessions (Session state server) it doesn't support if for IPC
of w3wp
s.
Of course you can write your own service (you should handle concurrency issues) but it's a lot of work and error prone. Use persistent data store unless you have high rate read/writes which brings a database to it's knees (rare applications are so performance critical).
Take a look at Velocity - it's a distributed cache for multiple applications on multiple servers, but would run happily on a single server.
精彩评论