Your caching methods will be based on your implementation. From what you described above, your service is a simple wrapper. This shell calls the class library (I use through threads), which executes the actual process.
With this design, I would suggest implementing your "caching services" in the class library. Although classes in your library are executed and then deleted, there is no reason why your class library cannot keep cache references after other classes in the library complete.
Personally, since the class library requires cached objects, I see no reason why the service needs access to these objects. In addition, by maintaining a cache in your class library, you can "hide" your cached objects. Finally, another big positive result is debugging, and fixing bugs will be much easier. Since you can run the class library inside any other application, you are not required to debug the Windows service, which can be quite a challenge.
I think the real question is what kind of caching should you use, this greatly affects the shared memory consumed. Now this is a different question.
You have a lot of options for caching. The most common in-memory caching is performed using the MemoryCache function as part of the .Net infrastructure. This supports expreration policies and a complete Cacheing wrapper similar to the ASP.Net web implementation.
MSDN for the memory cache: http://msdn.microsoft.com/en-us/library/system.runtime.caching.memorycache.aspx
In the end, in my opinion, I would probably transfer my caching system to another class, using Singletons or through DependencyInjection to support cached objects.
Hope this helps.
Niko
source share