asp.net - LINQ driven cache items invalidation -


i'm making asp.net mvc project , implement business data caching @ repository (linq2sql) layer. since entities related each other, need invalidate related ones when i'm invalidating base entity. have blog/post/comments relation , when user makes new comment need invalidate cached post entity since has outdated totalcomments field. there more complicated logic invalidation other entities.
well, need implement flexible invalidation mechanism purpose. i've found before:
- sql notifications service. notifies app each time table has changed. since i'll have high-loaded application, changes on tables gonna often. cached comments post drop each time new comment added.
- caching linq(or sql) queries. in case rendered query placed cache using hash key. not bad impossible drop "all comment entities having blogpostid = deletedblogpostid"

and idea is. wanna use linq queries on httpruntime.cache items find items deleted properties (e.g. in case of deleting blog post

cacheditem => cacheditem.gettype() == typeof(comment)         && ((comment)cacheditem).blogpostid == deletedblogpostid 

to delete related comments). can't find in google approach used. isn't way manipulate cached related entities? query performance on 1m cached items 600 ms on notebook.
thanks!

i call cache clearing method in controller corresponding object. example, if user editing individual post, in controller method handles post request should clear cache post.

using sql server notification services seems backwards me. server-side web application first point of entry users; database comes after. know when need clear cache in mvc application, why not clear cache there?

edit:

one other option storing data in cache , having access via key (so don't have iterate on entire cache collection):

httpruntime.cache.insert(string.format("commentsforpost-{0}", postid), value); 

where value list<comment> , postid id of post. way comment collection , cache keys dynamic. i've used approach across many applications (though write more generic less code duplication).


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -