是否可以在普通C#方法上使用类似于OutputCache的属性? [英] Is there an attribute similar to OutputCache that I can use on normal C# methods?

查看:111
本文介绍了是否可以在普通C#方法上使用类似于OutputCache的属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我喜欢如何在控制器操作上使用[OutputCache].

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

我有一些方法不是我想向其添加简单缓存的控制器操作,是否可以在非控制器操作上使用类似于[OutputCache]的方法?我有一种方法可以访问要缓存的Web服务,而与显示其数据的控制器操作无关.

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.

我只想要一个属性,该属性是用于普通方法的HttpContext缓存的包装.

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

推荐答案

AFAIK,没有内置内容.但是,如果您愿意的话,您可以建造一个.如果您使用的是.NET 4.0,则可以使用 System.Runtime.Caching 程序集,它提供了许多在.NET应用程序(不仅是Web应用程序)中缓存数据的有用方法.您也可以看看称为函数备注的技术

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.

这篇关于是否可以在普通C#方法上使用类似于OutputCache的属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆