如何使用 Outputcache 保存列表所有用户都可以看到?
大家好,我有一个列表,我想向所有用户显示相同的列表,而不需要在我的数据库中进行其他查询。 在论坛上搜索我发现 OutPutCache 是我可以遵循的最佳方法,但我真的不明白我该怎么做。
[编辑]
OutPutCache 是做到这一点的最佳方法吗?
Hello guys I have a List that I want to show for all users the same list without make an other query at my database.
Searching on forums I found that OutPutCache is the best way that I can follow, but I really don't understand how can I do that.
[EDIT]
Is OutPutCache the best way to do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你已经走得太远了;如果您只想将一个
List
保留在内存中一段时间,则不需要输出缓存。输出缓存是指当您想要缓存整个呈现的页面以发送给用户而不调用控制器时。您只需要通过共享变量或普通的旧缓存将对象保留在内存中。
You're getting too far along here; if all you have is a single
List<T>
that you want to keep in memory for a while, you dont need output caching. Output caching is when you want to cache the entire rendered page to send to users without recalling your controller.You just need to persist the object in memory, either via a shared variable or plain old caching.
控制器方法上的 [OutputCache] 属性将缓存查询结果 - 如果使用 VaryByParam 参数,这将缓存该参数的结果,从而减少从控制器方法调用数据库的次数。
The [OutputCache] attribute on a controller method will cache the result of a query - if you use the VaryByParam parameter, this will cache the result for that parameter, reducing the number of calls to the database from the controller method.