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 6986935
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:52:20+00:00 2026-05-27T18:52:20+00:00

I have Outputcache attribute above one of my controller action in an ASP.NET MVC

  • 0

I have Outputcache attribute above one of my controller action in an ASP.NET MVC 3 application:

[OutputCache(Duration=86400)] // One day
public JsonResult GetCompanyName(int companyId)
{
    var company = _session.Get<Company>(companyId);

    if (company == null)
        throw new Exception();

    return Json(company.Name);
}

The reason behind the cache is that the companies we support doesn’t change so often, so we don’t need to query the data base for each HttpRequest with the same parameter.

If we add a new company how can I force the “re-check”?
Can it be done to this action only or I have to delete all my app cache?

Update: My data base is Oracle and my ORM is NHibernate

  • 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-05-27T18:52:20+00:00Added an answer on May 27, 2026 at 6:52 pm

    You could use the RemoveOutputCacheItem method. So let’s suppose that you have called the method like this to fetch the companies:

    /somecontroller/getcompanyname/123
    

    In order to expire this url from the cache so that the next time it is called it gets fresh results:

    public ActionResult Expire()
    {
        Response.RemoveOutputCacheItem("/somecontroller/getcompanyname/123");
        return Content("The cache was expired for the company with id = 123");
    }
    

    But IMHO for this scenario it would be better to use the second level cache of NHibernate to cache the results instead of caching the entire action with the OutputCache attribute. All that this action does is to return the JSON serialized object that came from the database. What is expensive is not the action call but the database call. So cache only the results of this database call (either using your ORMs cache or the system cache providers) as this will provide you with more robust control over the expiration policies of this cache.

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

Sidebar

Related Questions

Lately, i have been exploring the source code of OutputCache attribute in asp.net mvc-3
I have an ASP.NET MVC 3 application with an action that uses both the
I have one action has these attributes: [OutputCache(Location = System.Web.UI.OutputCacheLocation.Server, Duration = 300, VaryByParam
I have an asp.net mvc 3 project and I have a home controller. I
I have a simple MVC3 Controller Action like this [HttpGet] [OutputCache(Duration = 1200,Location=System.Web.UI.OutputCacheLocation.Server)] public
I have an ASP.net MVC 3 application running on IIS7. It is an e-commerce
I have the following action method: [HttpGet, Authorize, OutputCache(Duration = 60, VaryByHeader = Cookie,
I have an ASP.NET application, and am trying to output cache a certain page,
I have an ecommerce working in ASP.Net MVC. I'm using Caching to improve performance
If the controller action has the OutputCache attribute specified on an action, is there

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.