Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8025809
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T23:17:07+00:00 2026-06-04T23:17:07+00:00

I’m making an ASP.NET MVC project and i would like to implement business data

  • 0

I’m making an ASP.NET MVC project and i would like to implement business data caching at repository (LINQ2SQL) layer. Since entities are related to each other, i need to invalidate related ones when i’m invalidating some base entity. Say i have Blog/Post/Comments relation and when user makes a new comment then i need to invalidate cached Post entity since it has outdated TotalComments field. Sometimes there is as more complicated logic for invalidation other entities.
Well, i need to implement flexible invalidation mechanism for that purpose. What i’ve found before:
– SQL notifications service. It notifies the app each time table has changed. Since i’ll have high-loaded application, changes on some tables gonna be very often. All cached comments to any post will drop each time a new comment is added.
– Caching LINQ(or SQL) queries. In this case the rendered query is placed to the cache using its hash as a key. Not bad but it will be impossible to drop “all comment entities having BlogPostId = deletedBlogPostId”

And now what my idea is. I wanna use LINQ queries over HttpRuntime.Cache items to find items to be deleted by their properties (e.g. in case of deleting a blog post i look for

cachedItem => cachedItem.GetType() == typeof(Comment) 
       && ((Comment)cachedItem).BlogPostId == deletedBlogPostId

to delete all related comments). But i can’t find in google this approach is widely used. Isn’t it a good way to manipulate with cached related entities? Query performance over 1M cached items is 600 ms on my notebook.
Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T23:17:10+00:00Added an answer on June 4, 2026 at 11:17 pm

    I would just call a cache clearing method in your controller for the corresponding object. As an example, if a user is editing an individual post, then in the controller method that handles that POST request you should clear the cache for that post.

    Using SQL Server Notification Services seems backwards to me. Your server-side web application is the first point of entry for users; the database comes after. You know when you need to clear the cache in your MVC application, so why not clear the cache from there?

    Edit:

    One other option for storing your data in cache and having access to it via key (so you don’t have to iterate over the entire cache collection):

    HttpRuntime.Cache.Insert(string.Format("CommentsForPost-{0}", postId), value);
    

    Where value is a List<Comment> and postId is the id of your post. This way you could easily look up your comment collection and your cache keys are dynamic. I’ve used this approach across many applications (though I would actually write it to be more generic for less code duplication).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to count the length of a string with PHP. The string
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I would like to run a str_replace or preg_replace which looks for certain words
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.