MVC3数据缓存技术 [英] MVC3 data caching techniques

查看:87
本文介绍了MVC3数据缓存技术的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个sql查询(存储过程),大概需要8-10秒返回结果显示在webgrid之前。什么是asp.net-mvc3缓存的性能的最佳做法,所以用户不必每次打8-10秒就可以加载该数据(较少优化查询)?

I have a sql query (stored proc) that takes about 8-10seconds to return before the results are displayed in a webgrid. What is best practice for performance regarding cacheing in asp.net-mvc3 so the user doesn't have to take that 8-10sec hit everytime to load that data (less optimizing the query)?

推荐答案

您可以使用 MemoryCache 类,用于将此查询的结果存储在某些关键字下。关键可能是查询条件的哈希(如果有的话)。而且,有关如何使用MSDN的一些指南

You could use the MemoryCache class to store the result of this query under some key. The key could be the hash of the query criterias (if you have such). And here are some guides on MSDN on how to use it.

实现缓存时,请注意,默认情况下,此缓存存储在内存中。这意味着如果您在Web场中运行此应用程序,则使用分布式缓存可能更有意思,以便服务器场的所有节点都共享相同的缓存数据。这可以通过扩展 ObjectCache 类来完成与一些分布式缓存解决方案。例如 memcached 是受欢迎的,它具有 .NET提供者。另一种分布式缓存解决方案是 AppFabric

When implementing caching bear in mind that this cache is stored in memory by default. This means that if you are running this application in a web farm it might be more interesting to use a distributed cache so that all nodes of the farm share the same cached data. This could be done by extending the ObjectCache class with some distributed caching solution. For example memcached is a popular one and it has .NET provider. Another distributed caching solution is AppFabric.

这篇关于MVC3数据缓存技术的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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