简体   繁体   中英

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.

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM