<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>John Sheehan : Blog - Latest Comments in Pluggable ASP.NET CacheManager</title><link>http://justsayinmorewords.disqus.com/</link><description>A blog by John Sheehan</description><atom:link href="https://justsayinmorewords.disqus.com/pluggable_aspnet_cachemanager/latest.rss" rel="self"></atom:link><language>en</language><lastBuildDate>Thu, 17 Mar 2011 08:36:08 -0000</lastBuildDate><item><title>Re: Pluggable ASP.NET CacheManager</title><link>http://johnsheehan.me/blog/pluggable-aspnet-cachemanager/#comment-167100066</link><description>&lt;p&gt;the use of distributed cache like NCache (&lt;a href="http://www.alachisoft.com/ncache/index.html" rel="nofollow noopener" target="_blank" title="http://www.alachisoft.com/ncache/index.html"&gt;http://www.alachisoft.com/n...&lt;/a&gt; )or appfabric (&lt;a href="http://msdn.microsoft.com/en-us/windowsserver/ee695849" rel="nofollow noopener" target="_blank" title="http://msdn.microsoft.com/en-us/windowsserver/ee695849"&gt;http://msdn.microsoft.com/e...&lt;/a&gt; ) can also be a good option.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Choclate</dc:creator><pubDate>Thu, 17 Mar 2011 08:36:08 -0000</pubDate></item><item><title>Re: Pluggable ASP.NET CacheManager</title><link>http://johnsheehan.me/blog/pluggable-aspnet-cachemanager/#comment-25381140</link><description>&lt;p&gt;Hello, Guys if you are searching any good job so please visit &lt;a href="http://www.staffingpower.com" rel="nofollow noopener" target="_blank" title="www.staffingpower.com"&gt;www.staffingpower.com&lt;/a&gt; There are many jobs are waiting&lt;br&gt;&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">staffing9</dc:creator><pubDate>Thu, 10 Dec 2009 03:08:30 -0000</pubDate></item><item><title>Re: Pluggable ASP.NET CacheManager</title><link>http://johnsheehan.me/blog/pluggable-aspnet-cachemanager/#comment-3892440</link><description>&lt;p&gt;Hi! Great Explanation John! ASP.NET is one of my favorite subjects. Its performance is good but only on a single server environment as we try to scale out; it will not work smoothly. But distributed caching solves this problem. Distributed caching is scalable and highly reliable. Even Microsoft also realized it and come up with its own solution of distributed caching. I think we should look into it.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Edmartinez</dc:creator><pubDate>Wed, 19 Nov 2008 05:31:37 -0000</pubDate></item><item><title>Re: Pluggable ASP.NET CacheManager</title><link>http://johnsheehan.me/blog/pluggable-aspnet-cachemanager/#comment-3262364</link><description>&lt;p&gt;I forgot about the as operator having a constraint of having to be a reference type, let me amend my post:&lt;/p&gt;&lt;p&gt;var item = HttpRuntime.Cache[key];&lt;br&gt;return item is T ? (T) item : default(T);&lt;/p&gt;&lt;p&gt;Which is basically what the as operator does anyway.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">dotnetchris</dc:creator><pubDate>Thu, 23 Oct 2008 16:46:43 -0000</pubDate></item><item><title>Re: Pluggable ASP.NET CacheManager</title><link>http://johnsheehan.me/blog/pluggable-aspnet-cachemanager/#comment-3245479</link><description>&lt;p&gt;The method is Generic, not the class, so you can't use as with T (The type parameter 'T' cannot be used with the 'as' operator because it does not have a class type constraint nor a 'class' constraint). You could add a type constraint, but it would limit what types you could specify when calling the method.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">John Sheehan</dc:creator><pubDate>Wed, 22 Oct 2008 22:32:26 -0000</pubDate></item><item><title>Re: Pluggable ASP.NET CacheManager</title><link>http://johnsheehan.me/blog/pluggable-aspnet-cachemanager/#comment-3236343</link><description>&lt;p&gt;Only one thing I'd add to the code Maarten posted, I would recommend using the AS operator instead of a direct case, and make it a one line operation.&lt;/p&gt;&lt;p&gt;return HttpRuntime.Cache[key] as T;&lt;/p&gt;&lt;p&gt;This will automatically return default(T) if the cached item doesn't exist. Using Maarten's code if you try to get an object from the cache that can not correctly cast to the type T you will get can't convert exception for the object.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">dotnetchris</dc:creator><pubDate>Wed, 22 Oct 2008 16:11:28 -0000</pubDate></item><item><title>Re: Pluggable ASP.NET CacheManager</title><link>http://johnsheehan.me/blog/pluggable-aspnet-cachemanager/#comment-3038864</link><description>&lt;p&gt;If you want to add provider-independent code you can perfectly use something like an adapter, which implements ICacheProvider (which you could have done with CacheManager) and takes a ICacheProvider instance and then proxy the calls and do your extra logic.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Guest</dc:creator><pubDate>Tue, 14 Oct 2008 05:34:05 -0000</pubDate></item><item><title>Re: Pluggable ASP.NET CacheManager</title><link>http://johnsheehan.me/blog/pluggable-aspnet-cachemanager/#comment-3023632</link><description>&lt;p&gt;That is correct. However, if your CacheManager contains additional logic that is provider-independent (not demonstrated here), then you'd want to use the example code.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">John Sheehan</dc:creator><pubDate>Mon, 13 Oct 2008 11:49:16 -0000</pubDate></item><item><title>Re: Pluggable ASP.NET CacheManager</title><link>http://johnsheehan.me/blog/pluggable-aspnet-cachemanager/#comment-3022723</link><description>&lt;p&gt;No you don't, what is the difference between&lt;/p&gt;&lt;p&gt;ICacheProvider cache = new ShortTermProvider();&lt;/p&gt;&lt;p&gt;or&lt;/p&gt;&lt;p&gt;CacheManager cache = new CacheManager(new ShortTermProvider());&lt;/p&gt;&lt;p&gt;&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Guest</dc:creator><pubDate>Mon, 13 Oct 2008 10:58:57 -0000</pubDate></item><item><title>Re: Pluggable ASP.NET CacheManager</title><link>http://johnsheehan.me/blog/pluggable-aspnet-cachemanager/#comment-3022549</link><description>&lt;p&gt;Thanks for the Explanation Maarten!&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">John Sheehan</dc:creator><pubDate>Mon, 13 Oct 2008 10:56:55 -0000</pubDate></item><item><title>Re: Pluggable ASP.NET CacheManager</title><link>http://johnsheehan.me/blog/pluggable-aspnet-cachemanager/#comment-3018732</link><description>&lt;p&gt;Great post, I've got something similar on my end.&lt;br&gt;One thing though, and that is that in your implementations of the Get-method you access the storage twice. One time to check if there is anything in storage, and another time to actually get it. Since you don't lock anything, another thread can remove the item you are looking for. This will happen when you use the storage frequently.&lt;/p&gt;&lt;p&gt;Something like the following will solve this.&lt;/p&gt;&lt;p&gt;public T Get&amp;lt;t&amp;gt;(string key)&lt;br&gt;{&lt;br&gt;  T item = (T)HttpContext.Current.Cache[key];&lt;br&gt;  if (item == null)&lt;br&gt;    item = default(T);&lt;br&gt;  return item;&lt;br&gt;}&lt;/p&gt;&lt;p&gt;&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Maarten Oosterhoff</dc:creator><pubDate>Mon, 13 Oct 2008 02:27:50 -0000</pubDate></item><item><title>Re: Pluggable ASP.NET CacheManager</title><link>http://johnsheehan.me/blog/pluggable-aspnet-cachemanager/#comment-3015115</link><description>&lt;p&gt;Can you elaborate on this a little more? I've never come across anyone &lt;br&gt;discussing locks and caching (at least in regards to ASP.NET) before. I &lt;br&gt;think it would be interesting to hear what the risk is of not using a lock.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">John Sheehan</dc:creator><pubDate>Sun, 12 Oct 2008 19:47:11 -0000</pubDate></item><item><title>Re: Pluggable ASP.NET CacheManager</title><link>http://johnsheehan.me/blog/pluggable-aspnet-cachemanager/#comment-3013689</link><description>&lt;p&gt;Just a quick one on this...&lt;/p&gt;&lt;p&gt;lock the cache when you're writing to it, for occasions where data is being refreshed by another process.&lt;/p&gt;&lt;p&gt;        lock (HttpContext.Current.Cache)&lt;br&gt;        {&lt;/p&gt;&lt;p&gt;        }&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Paul</dc:creator><pubDate>Sun, 12 Oct 2008 18:03:03 -0000</pubDate></item><item><title>Re: Pluggable ASP.NET CacheManager</title><link>http://johnsheehan.me/blog/pluggable-aspnet-cachemanager/#comment-3010900</link><description>&lt;p&gt;I honestly didn't realize that this was the Strategy Pattern (I'm not well versed in patterns), but you are correct sir.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">John Sheehan</dc:creator><pubDate>Sun, 12 Oct 2008 14:33:05 -0000</pubDate></item><item><title>Re: Pluggable ASP.NET CacheManager</title><link>http://johnsheehan.me/blog/pluggable-aspnet-cachemanager/#comment-3010880</link><description>&lt;p&gt;The problem with using parameter is that if you have a lot of calls in a class, you have to update them all if you want change providers.&lt;/p&gt;&lt;p&gt;The example above is perfect for if you need different caching strategies in a project. Just create a provider for each strategy and use that provider when needed.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">John Sheehan</dc:creator><pubDate>Sun, 12 Oct 2008 14:29:53 -0000</pubDate></item><item><title>Re: Pluggable ASP.NET CacheManager</title><link>http://johnsheehan.me/blog/pluggable-aspnet-cachemanager/#comment-3005587</link><description>&lt;p&gt;In other words....its the strategy pattern for caching? :)&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Bart Czernicki</dc:creator><pubDate>Sun, 12 Oct 2008 01:23:50 -0000</pubDate></item><item><title>Re: Pluggable ASP.NET CacheManager</title><link>http://johnsheehan.me/blog/pluggable-aspnet-cachemanager/#comment-3005502</link><description>&lt;p&gt;Have you put any thought into this IoC approach when you require a CacheDependency? I basically took your approach and created a new Store method that took CacheDependency as a parameter.&lt;/p&gt;&lt;p&gt;I'm a fan of the whole loosely coupled thing, however there are some times that I require (well, want more then require) a few different caching strategies for one project. Very data dependent of course. Any thoughts?&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Betty</dc:creator><pubDate>Sun, 12 Oct 2008 01:06:14 -0000</pubDate></item><item><title>Re: Pluggable ASP.NET CacheManager</title><link>http://johnsheehan.me/blog/pluggable-aspnet-cachemanager/#comment-3002853</link><description>&lt;p&gt;CacheManager cache = new CacheManager(new ShortTermProvider()); // the constructor of CacheManager should be uses in looser way.&lt;/p&gt;&lt;p&gt;You should take a look at some Dependency Injection framework (castle, &lt;a href="http://spring.net" rel="nofollow noopener" target="_blank" title="spring.net"&gt;spring.net&lt;/a&gt;, Nunit) and apply it instead of creating new CacheManager directly in code.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">duy lam</dc:creator><pubDate>Sat, 11 Oct 2008 21:11:15 -0000</pubDate></item><item><title>Re: Pluggable ASP.NET CacheManager</title><link>http://johnsheehan.me/blog/pluggable-aspnet-cachemanager/#comment-3001874</link><description>&lt;p&gt;Why do you call the method destroy?? &lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">flalar</dc:creator><pubDate>Sat, 11 Oct 2008 18:36:53 -0000</pubDate></item><item><title>Re: Pluggable ASP.NET CacheManager</title><link>http://johnsheehan.me/blog/pluggable-aspnet-cachemanager/#comment-2983748</link><description>&lt;p&gt;I've written something of the sort a while back..(not as good as yours), but I did something like this:&lt;/p&gt;&lt;p&gt;public static Cache Cache {&lt;br&gt;            get {&lt;/p&gt;&lt;p&gt;                if (System.Web.HttpContext.Current != null &amp;amp;&amp;amp; System.Web.HttpContext.Current.Cache != null)&lt;br&gt;                    return System.Web.HttpContext.Current.Cache;&lt;/p&gt;&lt;p&gt;                return System.Web.HttpRuntime.Cache;&lt;/p&gt;&lt;p&gt;            }&lt;br&gt;        }&lt;/p&gt;&lt;p&gt;That allows me to utilize the same concepts in Windows Forms and Windows Service applications....just some FYI&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Brian</dc:creator><pubDate>Fri, 10 Oct 2008 13:32:37 -0000</pubDate></item><item><title>Re: Pluggable ASP.NET CacheManager</title><link>http://johnsheehan.me/blog/pluggable-aspnet-cachemanager/#comment-2983595</link><description>&lt;p&gt;Great explanation Chris! Much better than I would have done.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">John Sheehan</dc:creator><pubDate>Fri, 10 Oct 2008 13:22:41 -0000</pubDate></item><item><title>Re: Pluggable ASP.NET CacheManager</title><link>http://johnsheehan.me/blog/pluggable-aspnet-cachemanager/#comment-2980371</link><description>&lt;p&gt;Steve,&lt;/p&gt;&lt;p&gt;I can offer some insight into the model that John was following when he created the cache manager. Following a pattern similar to this allows you to create loosely coupled code.&lt;/p&gt;&lt;p&gt;With your question if you implemented the caching solution using only the specific classes if you ever decided you wanted to change your caching backing store from HttpRuntime.Cache (note: John, you should reference the cache as HttpRuntime.Cache instead of Httpcontext.Current.Cache, calling the context just causes extra processing to just resolve to HttpRuntime.Cache) to a sql data store or to a memory caching solution like memcache or velocity you will now have to go into you code and change every single usage of RequestProvider to use MemCacheProvider or whatever other implementation you wish to use.&lt;/p&gt;&lt;p&gt;With a loosely coupled implementation that John created here, if you ever wish to switch from one provider to another you only ever need to change where it instantiates CacheManger to use the new provider instead. This brings me to my point about Enterprise Library's CacheManager having a factory method for creating the caching providers usage, this will allow you to only need to declare the CacheProviders once in your code and no matter how many times you change the concrete implmentation of ICacheProvider you will only ever need to change 1 line of code in the entirety of your project which is a great thing indeed.&lt;/p&gt;&lt;p&gt;This idea of creating shared services that you can plug and play based off of interfaces is the basis of the idea of  "Inversion of Control" or IoC that creates very robust and completely decoupled projects. Some of the most well known IoC frameworks are Microsoft's Unity, Spring.NET, Castle Windsor, Ninject, StructureMap to name a few there are quite a bit of frameworks out there for IoC. Creating loosely coupled code is definitely getting to the point where it is mandatory for a project to be a well made solution.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">dotnetchris</dc:creator><pubDate>Fri, 10 Oct 2008 11:13:40 -0000</pubDate></item><item><title>Re: Pluggable ASP.NET CacheManager</title><link>http://johnsheehan.me/blog/pluggable-aspnet-cachemanager/#comment-2980215</link><description>&lt;p&gt;This is a nice implementation of a basic caching solution. You should also be aware of the Enterprise Library Caching Application Block. it offers extensibility to add new cache providers and is very easy to integrate with other Enterprise Library blocks, from my own personal usage I used it with the Membership provider for caching user tokens/privileges.&lt;/p&gt;&lt;p&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/cc309103.aspx" rel="nofollow noopener" target="_blank" title="http://msdn.microsoft.com/en-us/library/cc309103.aspx"&gt;http://msdn.microsoft.com/e...&lt;/a&gt;&lt;/p&gt;&lt;p&gt;The big difference in implementation of the Caching block is that the providers are created through a singleton factory which in my opinion makes alot of sense since cache stores generally are only ever 1 and only 1 per type of store so relying on a factory to handle the management of instances of the providers makes sense to me more than doing new __Provider(....) anytime you wish to access the cache.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">dotnetchris</dc:creator><pubDate>Fri, 10 Oct 2008 11:03:34 -0000</pubDate></item><item><title>Re: Pluggable ASP.NET CacheManager</title><link>http://johnsheehan.me/blog/pluggable-aspnet-cachemanager/#comment-2979701</link><description>&lt;p&gt;What's the point in using CacheManager instead of just using the ICacheProvider instances?&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Guest</dc:creator><pubDate>Fri, 10 Oct 2008 10:32:50 -0000</pubDate></item><item><title>Re: Pluggable ASP.NET CacheManager</title><link>http://johnsheehan.me/blog/pluggable-aspnet-cachemanager/#comment-2939146</link><description>&lt;p&gt;I use a very similar approach for session variables as well.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Kevin Pang</dc:creator><pubDate>Wed, 08 Oct 2008 11:41:32 -0000</pubDate></item></channel></rss>