Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an attribute similar to OutputCache that I can use on normal C# methods?

I like how I can use [OutputCache] on my controller actions.

I have a few methods that aren't controller actions that I would like to add simple caching to, is there something similar to [OutputCache] that I could use on non-controller actions? I have a method which hits a web-service that I want cached independently of the controller action that displays its data.

I just want an attribute which is a wrapper around HttpContext cache for normal methods.

like image 499
I AM THE REAL BATMAN Avatar asked Aug 28 '11 20:08

I AM THE REAL BATMAN


1 Answers

AFAIK, there is nothing built-in. But you could build one if you will. If you are using .NET 4.0 you could use the System.Runtime.Caching assembly which provides many useful methods for caching data in .NET applications (not only web applications). You could also take a look at a technique called function memoization.

like image 59
Darin Dimitrov Avatar answered Nov 07 '22 05:11

Darin Dimitrov