Showing posts with label Cache. Show all posts
Showing posts with label Cache. Show all posts

Thursday, January 26, 2012

ASP.NET MVC OutputCache override


IE Strikes Again!

Because of my recent discovery of the IE9 “feature” that makes it cache unlike every other browser, I had to come up with a small change to our caching scheme on my project. To be fair, the IE9 team is actually well within RFC definitions of how to handle “cache-control: private”, so I shouldn’t complain too much about it. Though, why is it always IE that causes me to do extra coding?

Anyway, my solution was to add a “Default” OutputCache setting for all my MVC Controllers and then, to override these options on individual Controller Actions when needed.  The problem is: I can’t find any information on whether or not an OutputCache directive on an Action will override one on the Controller.

So, I wrote a quick test app to test it out. 

The Code

    // default everything to a tiny cache time
    [OutputCache(CacheProfile="ShortCache")]
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            ViewBag.Message = "Welcome to ASP.NET MVC!";
            return View();
        }

        // change to a longer cache time
        [OutputCache(CacheProfile = "LongCache")]
        public ActionResult About()
        {
            return View();
        }
    }

Web.config mods

  
<system.web>
      <caching>
        <outputcachesettings>
          <outputcacheprofiles>
            <add duration="1" name="ShortCache" varybyparam="*">
            <add duration="60" name="LongCache" varybyparam="*">
          </add></add></outputcacheprofiles>
        </outputcachesettings>
      </caching>
  </system.web>

Results

Well, What do you know!? It worked! Hopefully someone else stumbles across this and saves themselves some time.

Wednesday, October 26, 2011

Windows Azure AppFabric Cache's Miniscule Features

 

Just wanted to warn/inform people who are considering using AppFabric Caching in Azure…

Here’s a list of things it won’t do:

  • Regions
  • Named Caches
  • Allow you to get a list of cache keys currently in use
  • High Availability Mode (redundant copies across machines for durability)
  • No sliding window expiration
  • No events for things like eviction, add/remove, etc.
    • so you can’t update a local cache with events from the global cache
    • You don’t get notified if something is removed, so you only know when you get “null” back from a Get()
  • No Powershell integration (if you’re into that)
  • No tag support (tagging is basically used for some extra metadata besides the key without pulling the whole object)

So, basically, ALL you get is a simple, Get/Set distributed cache that doesn’t even support the whole set of features you get from the basic ObjectCache in .NET 4.0

They really shouldn’t be calling it “AppFabric Cache” at all, since it doesn’t really support anything that comes with that API

I must say that I’m really disappointed

We waited a LONG time for this feature and got something that could have been coded in a month.

Bad form, Microsoft.  Bad form!