Caching across Applications in .Net on a Windows Machine - c#

I am trying to implement caching in .Net such that the cached data is accessible not just by an application that may run multiple times on the same machine but by other types of applications that may run on the machine. They could be windows services, web services, win forms etc.
I have looked at System.Runtime.Caching (because Enterprise Application Blocks Caching is going to become obsolete) as a means to achieve this. The default MemoryCache is insufficient to achieve this as I don't believe that it work across app domains.
Is there a way I can implement the kind of caching I am looking for or is there a caching dll of some sort (must be free) that I can use to achieve my goal?
Is there a way to use System.Runtime.Caching with IsolatedStorage scoped to MachineLevel?
I've looked at memcache too and can't use it because we need this to run on windows machines. I started looking at SharedCache (http://www.codeproject.com/KB/web-cache/AdvanceCaching.aspx) and am curious about the pitfalls it has as well.
Thanks.
-- Revision 1 --
I think the optimal solution for me would use the Caching object to a Memory Mapped File (http://msdn.microsoft.com/en-us/library/dd997372.aspx). So the question I have now is whether anyone has done that with the System.Runtime.Caching object. There must be a way to extend it if necessary...examples of how to do so would also be much appreciated.

You're looking for AppFabric Cache. It's a Windows Server technology from Microsoft. It's free.
I should also say that if you like memcached, you can use that on Windows as well, and in fact Microsoft Azure team members used to recommend it, before the AppFabric caching was available on Windows Azure.

Have you evaluated Microsoft Velocity? Take a look - I believe if you are not okay with using the AppFabric Cache, this should work out for you:
http://msdn.microsoft.com/en-us/magazine/dd861287.aspx#id0450004
For simple client based caching, you can look at file based caching.

Related

What are practical performance limitations of self-hosted owin/Nancy web server?

It is pretty clear that if you are developing a web UI for a desktop/server application owin/nancy hosting is a logical choice. It is also clear that for high traffic web site that would not be sufficient, but IIS hosting is preferable.
I would like to know what are the practical considerations / limitations when using self-hosted web app. Let's assume that we do not need any IIS provided functional features such as, say gzip compression. From pure performance point of view, at which load level (approximately) self-hosting starts breaking down, and why? Does IIS do thread scheduling more efficiently then owin host?
There is no official documentation by Microsoft answering this question. Nevertheless you can find some comparisons through google like this. From my personal experience, self hosted applications should and are performing better than IIS just because the last one creates much overhead for the features it's providing, while self hosted is based on pure TCP connections with much less steps before it's getting to your actual controller.
As Evk already mentioned in comments, people picking up IIS just because they simply need some features it's providing. It's also a case when people don't want to manage application full lifecycle (along with self hosted you will need to create windows service or run it manually each time), IIS simply providing you a possibility set it up once and whenever your machine is running - webpage is available, as simple as that.
I have never heard any concerns about self hosted performance even though we built really huge systems based on that. Hope that helps!
P. S. I wouldn't really expect any link to Microsoft's comparison page as it would be pretty surprising they're telling that IIS (their product) worse than self hosted from performance perspective, telling to not use it for highly loaded apps. IIS is advertised as solution for enterprise.

Is System.Web.Caching or System.Runtime.Caching preferable for a .NET 4 web application

I am adding caching to an ASP.NET web application. This is .NET 4, so I can use the classes in the System.Runtime.Caching namespace (which, as I understand it, was added to provide similar functionality to that found in System.Web.Caching, but for non-Web-apps.)
But since this is a web app, am I better off using System.Web.Caching? Or is the newer System.Runtime.Caching superior in some way?
Microsoft recommends using System.Runtime.Caching for all caching purposes. See this: http://msdn.microsoft.com/en-us/library/dd997357.aspx
Although, I have come across a couple threads where people are having issues with the MemoryCache.Default instance. After a while, it stops working properly. Any item you add using the Add or Set method does not actually get added to the cache. I tried the same and was able to reproduce this issue with explicitly calling MemoryCache.Default.Dispose() method.
Here are the links:
MemoryCache Empty : Returns null after being set
http://forums.asp.net/t/1736572.aspx/1
My recommendation is to use the System.Web.Caching (HttpContext.Current.Cache)
UPDATE:
This issue has been fixed by MS. Check the accepted answer in the post below:
Runtime Cache Issue Resolved
System.Runtime.Caching allows you to cache across all .Net apps, not just the IIS worker process. So if you have a requirement that will access the cache in multiple scenarios, use System.Runtime. Also you can check this cache adapter which allows you to swap between runtime, web, and app fabric caching. https://bitbucket.org/glav/cacheadapter
One more thing, if you have a multi-server farm, with a load balanced configuration make sure you have sticky-sessions or a distributed cache model.

Framework/Dll/... to manage a cache + polling to a service

I remark that for my project I really need often something to manage a cache of our data(for data access performance, for offline work, ...).
So I was asking me if there was something which could respond to my needs or if I will have to create my own framework for this. It can be only a "Core" which furnish the logic, and we have to implement the business part.
My needs are:
Data sources can be WCF/Web service/...(this part should be implemented on every new project
It has to manage an store of data
available
This store must be refreshed regularly by polling the service
This store can be persistent(write cache on disk for the next start)
The framework must allows modifications, online and offline,
asynchronous and synchronous(if online)
It has to run with c# 4.0
If the local cache store can be accessed through LINQ, it would be great(like directly through a list
The concurrency has to be managed(or offer us a way to manage it)
The use/configuration of this framework should be shorter than implement myself it every time
So here we are, do you know a tools which can fits into my query?
Somebody tell me that MS entreprise library should have something like that, but I didn't found anything.
Thank you!
You could have a look at
Windows Server AppFabric. It used to be called 'velocity'.
It is a distributed in-memory application cache platform for
developing scalable, high-performance applications.
Otherwise, the Enterprise Library Caching Application Block you're talking about is here: The Caching Application Block however, this page says:
Caching Application Block functionality is built into .NET Framework
4.0; therefore the Enterprise Library Caching Application Block will
be deprecated in releases after 5.0. You should consider using the
.NET 4.0 System.Runtime.Caching classes instead of the Caching
Application Block in future development.
And actually, the System.Runtime.Caching Namespace is a very good building block to build on if you're going to write something by yourself. I don't think it implements the notion of distributed cache, that's why Windows Server AppFabric exists.
Now, there is also non-Microsoft technologies available in the .NET space. Have a look a memcached and .NET implementation or usage:
Is there a port of memcache to .Net?
Memcached with Windows and .NET
You also have commercial packages available, like NCache (I'm not affiliated). I don't know what they provide, but it's also probably interesting to have a look at it, just to be aware what they provide, to ensure you don't miss any feature you'd need later one.
Have a look at SharedCache.

Best practices for user settings/configuration in a c# client app

I am working on a .NET app that will also run on iphone via monotouch and osx/linux via mono. The app will hold profiles for various users and the profile used for a particular session will be selected on startup, kind of like Skype.
To store per-user settings, I am considering using the Application Settings system that's part of .NET. However, this system seems to rely on reflection, which is not available on iphone. I am also not sure if this system will function on platforms other than Windows.
I could also use the app's sqlite database that stores the application data to store settings, and simply roll my own settings classes that would be serialized/deserialized to the sqlite database like all the other application data.
Finally I could roll my own file-based solution.
What are the tradeoffs for these approaches? Why does .NET have dedicated support for user settings? It seems like a quite simple thing that coders should do on their own, and the existence of dedicated support within the .NET framework makes me suspect that I'm missing some point of complexity.
Thanks!
First thought - don't use configuration settings, use the sqlite database as that is on the iPhone and the best approach to take. Remember MonoTouch just transliterates the .NET code to the Objective C equivalent code and compiled to native binary, and you may run into snags if you use Windows/Mono specific code that may not be present on the iPhone.
Avoid pinvokes like the plague if you want your code to work across all platforms.
.Net has support for user settings because Microsoft designed them that way.
Hope this helps,
Best regards,
Tom.

Is it possible to set cache in one application and use it in another application?

Is it possible to set cache in one application and use it in another application ?
Short answer is Yes. Regardless of the language you are using you can use a product such as MemCached (linux/unix), MemCached Win32 (windows), Velocity (Microsoft) in which such products are used for caching farms.
A caching farm is similar to a web farm in that it is a high availability and easily scalable solution...for caching. In this case the cache is totally separate from the application itself. So as long as you have a naming structure for your keys (assigned to the objects in the cache) you could technically span the cached content across not only applications but different platforms, languages, technologies, etc.
See more information regarding this here: System.Web.Caching vs. Enterprise Library Caching Block
You should really be much more specific in your questions. I have to assume you're talking about ASP.NET and the Cache property, but it's only a guess, since you didn't give any clue about what you're looking for (except that you said C#).
No, the Cache property is per-application.
Implement your caching functionality in one application and make it available through .Net Remoting.
Then access it from your other application. Remember that all your objects you want to cache this way will have to be serializable. (you probably have to serialize/deserialize it on your end. not the cache app end)

Categories