简体   繁体   English

ASP.NET数据缓存以及如何使其无效

[英]ASP.NET Data Caching and how to invalidate

My web application is using the asp.net cache object to store data from the database. 我的Web应用程序正在使用asp.net缓存对象来存储数据库中的数据。 I am looking for an elegant to invalidate cache objects but haven't come up with anything elegant yet. 我正在寻找一种优雅的方法来使缓存对象无效,但是还没有提出任何优雅的方法。

It is easy to invalidate a single record or a list of all records in a single table, by keeping track of their cache keys. 通过跟踪其缓存键,很容易使单个记录或单个表中所有记录的列表无效。 However I may have any number of lists of subsets of a table's data. 但是,我可能有任何数量的表数据子集列表。 I would like to invalidate only the cache records of the lists that contain a particular record, when that record changes. 当该记录更改时,我只想使包含特定记录的列表的缓存记录无效。 I don't want to have to invalidate all the lists of data for that table if only one of the lists contain that record. 如果仅其中一个列表包含该记录,我就不必使该表的所有数据列表都失效。

I have tried SqlDependency and not happy with it as I've run into a lot of issues. 我尝试了SqlDependency,但由于遇到很多问题而对此不满意。 Do you have any idea how to attack this problem? 您知道如何解决这个问题吗? Thanks in advance! 提前致谢!

create a static Dictionary<string, List<string>> 创建一个静态Dictionary<string, List<string>>

the key will use a naming scheme like table_primarykey which represents a single record 该键将使用诸如table_primarykey之类的命名方案,该方案表示单个记录

the value is a list of cache key names that the record is cached in 该值是记录在其中缓存的缓存键名称的列表

this will let you effectively find what records are cached where, permitting that you manage the dictionary while adding and removing items (use a callback) from the cache. 这将使您有效地查找在哪里缓存了哪些记录,从而允许您在从缓存中添加和删除项(使用回调)的同时管理字典。

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

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