Search code examples
wpfcachingrouted-commandscanexecute

Cache CanExecute (or anything) in WPF?


The Cache object in System.Web is pretty freaking nice.

I handle my CommandBinding.CanExecute sort of like this:

CommandBindings[0].CanExecute += (s, e) =>
{
    e.CanExecute = NotInsignificantRoutine();
};

In my scenario, the return value of NotInsignificantRoutine() doesn't change inside a 5 second window. What would be the best way to cache in WPF? Import System.Web?


Solution

  • Ah, I didn't know about this; here:

    The System.Runtime.Caching namespace is new in the .NET Framework 4. This namespace makes caching is available to all .NET Framework applications. In previous versions of the .NET Framework, caching was available only in the System.Web namespace and therefore required a dependency on ASP.NET classes.

    http://msdn.microsoft.com/en-us/library/dd997362.aspx