jQuery 自动完成的服务器端缓存策略?
我正在我的网站上实现多个标记字段,其中包括使用 jquery UI 插件的自动完成选项。我一切正常,虽然小部件本身并不像我希望的那样强大(例如,有没有办法使列表中的第一项始终突出显示),但它现在可以使用。
我的问题是关于处理服务器端对自动完成数据的请求。现在,我正在使用 AJAX 来检索所提供的输入术语的潜在匹配项。我正在访问的表中有大约 10,000 条记录,我的想法是,我可以将这些记录的列表缓存在我的服务器上的共享/静态属性中,而不是不断查询该表(我使用的是 ASP.NET)。 NET MVC 与 SQL Server 后端)并查询该列表。我会每 4 小时左右刷新一次列表,以使其保持最新状态。
这个想法显然是为了减轻 SQL 服务器的压力并最大限度地提高自动完成下拉列表的性能。 我最终想知道的是,在我的服务器内存中保存 10,000 个值的列表/数组是否是一种不好的做法?这里有已知的限制/阈值吗? 我的服务器有 2GB RAM,无论如何可能需要尽快升级。
任何建议将不胜感激。
感谢您抽出时间!
I am in the process of implementing several tagging fields on my website that include an autocomplete option using the jquery UI plugin. I have everything working, and while the widget itself isn't as robust as I would prefer (is there a way to make the first item in the list always highlighted, for instance), it is serviceable for now.
My question is around handling the server-side requests for the autocomplete data. Right now I'm using AJAX to retrieve the potential matches for the supplied input term. The table I'm hitting has around 10,000 records in it, and my thought was that rather than constantly querying that table, I could just cache a list of those records in a shared/static property on my server (I'm using ASP.NET MVC with a SQL Server backend by the way) and query that list instead. I would refresh the list every 4 hours or so, just to keep it up to date.
The idea is obviously to reduce the strain on my SQL server and maximize the performance of the autocomplete drop down. What I'm ultimately wondering is if it's bad practice to keep a list/array of 10,000 values in memory on my server; is there a known limit/threshold here? My server has 2GB of RAM, and may need to be upgraded soon anyway.
Any suggestions would be much appreciated.
Thanks for your time!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
10,000 个小字符串应该不会太糟糕 - 我以前就这样做过,没有明显的副作用。
我建议在没有内存项目的情况下运行您的应用程序,然后再次运行,并在 Windows 的任务管理器中查看内存和 CPU 使用情况,只是为了了解您真正使用了多少内存 - 这将有所帮助确定它是否会在以后造成问题。
但每次访问数据库可能也不会那么糟糕 - 除非您有大量流量,否则影响可能可以忽略不计。
10,000 small strings shouldn't be too bad - I've done that before with no noticeable side effects.
I would recommend running your app without the items in memory, and then again with, and take a look at memory and CPU usage in Task Manager in Windows, just to get an idea of how much memory you truly are using up - that will help determine if it will cause problems down the road.
But hitting the database each time probably wouldn't be that bad either - unless you hae a ton of traffic, the effect would likely be negligible.
为什么不使用由ASP.NET MVC。它比将它们存储在内存中更好,只需让框架为您处理即可。
您可以轻松设置超时等。
Why dont you use the OutputCache attribute provided by asp.net mvc. Its better than storing them in memory, just let the framework handle it for you.
You can easily set your timeout, etc.