简体   繁体   English

ASP.net - 如何将记录集放入缓存

[英]ASP.net - How to put a recordset in cache

I have around 100 rows in database ( which can increase in future ) for different labels used in page.对于页面中使用的不同标签,我在数据库中有大约 100 行(将来可能会增加)。 These rows are required on all pages.所有页面都需要这些行。 I want to do it in a way that I get these rows once from db and put some where in cache or something similar to that.我想以一种从 db 获取这些行一次并将一些位置放在缓存中或类似的东西的方式来做到这一点。 So that i don't have to query database on every page refresh.这样我就不必在每次页面刷新时查询数据库。 And how can this cache be used by all site visitors?所有站点访问者如何使用此缓存?

You can use Cache Variables something like this:您可以使用类似这样的缓存变量:

Cache["COMMON_DATA"] = lstData (This can be any collection like LIST<Country>)

You can also use SqlCacheDependency in asp.net that will auto reset your cache if more rows are added in the the database您还可以在 asp.net 中使用 SqlCacheDependency,如果在数据库中添加更多行,它将自动重置缓存

else you can update the Cache again manually after inserting data in the table否则您可以在表中插入数据后再次手动更新缓存

Caching in ASP.net and Application State would be a couple of ideas for you.在 ASP.netApplication State中缓存对您来说是一些想法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM