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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:17:10+00:00 2026-06-15T06:17:10+00:00

Does anyone know if it’s possible to cancel output caching in code? What I

  • 0

Does anyone know if it’s possible to cancel output caching in code? What I mean is if I place output caching on a child action as follows can I then based on a condition cancel that caching from inside the child action?

[ChildActionOnly]
[OutputCache(Duration = 36000, VaryByParam="tagslug")]
public virtual ActionResult MostViewed(string tagslug, int count)
{
    // Make an API call here. If not data returned do not cache the ChildAction as specified above
}
  • 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-15T06:17:11+00:00Added an answer on June 15, 2026 at 6:17 am

    Skimming the framework source it looks like the only logic is don’t-cache-on-exception:

    // Only cache output if this wasn't an error
    if (!wasException) {
        ChildActionCacheInternal.Add(uniqueId, capturedText,
                                     DateTimeOffset.UtcNow.AddSeconds(Duration));
    }
    

    I can’t see a brilliant way to solve this: I think you’ll have to make your own custom OutputCachingAttribute based on the original source from the ASP.NET MVC source from CodePlex, and then either add an extra check to that line for the output returned e.g.

    if (!(wasException || capturedText.Contains("results:0"))) {
    

    or similar, or find a way to pass that code a flag to this from your controller. The existing code uses an object to store a value on the session; you could copy this, e.g.

    1. define a new static object key the same as _childActionFilterFinishCallbackKey e.g. _noCacheResultKey
    2. add a public static method to the attribute that you can call e.g.

      public static void FlagNoCache(HttpContext httpContext) {
          httpContext.Items[_noCacheResultKey] = true;
      }
      
    3. extend ClearChildActionFilterFinishCallback to remove this from .Items[] as well as the callback
    4. extend the above test to check this too e.g.

      if (!(wasException
            || filterContext.HttpContext.Items.ContainsKey(_noCacheResultKey))) {
      
    5. from your controller call MyOutputCacheAttribute.FlagNoCache(Context); as necessary.

    It may also be possible to throw an exception from your code and then catch it in a different IExceptionFilter so that it doesn’t get passed up beyond the OutputCacheAttribute but I don’t know how sorry.

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

Sidebar

Related Questions

Does anyone know how I can, in platform-independent C++ code prevent an object from
Does anyone know how can I convert this code to standard css? It's not
Does anyone know if there is a way to generate different code in the
Does anyone know of any websites, or (preferably) downloadable packages that you can use
Does anyone know how I can directly access a function from a PHP class
Does anyone know of any existing solutions using javascript that can parse a crontab
Does anyone know if it's possible to create a listener to detect when a
Does anyone know how I can open an attachment from a work item without
Does anyone know how i can grab a js object key that is in
Does anyone know of any existing packages or libraries that can be used to

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.