如何缓存ASP.NET用户控件?

时间:2021-12-07 15:54:09

I heard on a recent podcast (Polymorphic) that it is possible to cache a user control as opposed to the entire page.

我在最近播客(Polymorphic)上听说可以缓存用户控件而不是整个页面。

I think my header control which displays static content and my footer control could benefit from being cached.

我认为我的标题控件显示静态内容和我的页脚控件可以从缓存中受益。

How can I go about caching just those controls?

我怎样才能缓存那些控件呢?

2 个解决方案

#1


4  

Take a look here
You can use VaryByParam and VaryByControl in the output cache.

看一下这里你可以在输出缓存中使用VaryByParam和VaryByControl。

#2


1  

I think you can specify OutputCache in the control's markup file like you'd do on an ASPX page. And it'd get properly cached automatically.

我认为你可以在控件的标记文件中指定OutputCache,就像在ASPX页面上一样。并且它会自动正确缓存。

Just read up on OutputCache page directive on MSDN and get the parameters right and it should do what you want it to.

只需阅读MSDN上的OutputCache页面指令并获取正确的参数,它应该按照您的意愿执行。

It's been a long time since I write classic ASP.NET but I believe that's how it's done.

自从我编写经典ASP.NET以来已经很长时间了,但我相信它是如何完成的。

#1


4  

Take a look here
You can use VaryByParam and VaryByControl in the output cache.

看一下这里你可以在输出缓存中使用VaryByParam和VaryByControl。

#2


1  

I think you can specify OutputCache in the control's markup file like you'd do on an ASPX page. And it'd get properly cached automatically.

我认为你可以在控件的标记文件中指定OutputCache,就像在ASPX页面上一样。并且它会自动正确缓存。

Just read up on OutputCache page directive on MSDN and get the parameters right and it should do what you want it to.

只需阅读MSDN上的OutputCache页面指令并获取正确的参数,它应该按照您的意愿执行。

It's been a long time since I write classic ASP.NET but I believe that's how it's done.

自从我编写经典ASP.NET以来已经很长时间了,但我相信它是如何完成的。