简体   繁体   中英

ASP.NET Data Caching and how to invalidate

My web application is using the asp.net cache object to store data from the database. 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. Do you have any idea how to attack this problem? Thanks in advance!

create a static Dictionary<string, List<string>>

the key will use a naming scheme like table_primarykey which represents a single record

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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