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

  • Home
  • SEARCH
  • 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 6856015
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:49:53+00:00 2026-05-27T01:49:53+00:00

We are refactoring our site to use an external cache and the first step

  • 0

We are refactoring our site to use an external cache and the first step we took was using a custom OutputCacheProvider. First, we created a simple provider that just wraps MemoryCache and found problems with the way we are managing dependencies.

We have a custom OutputCacheAttribute that adds an extra key dependency to be able to invalidate a set of pages when certain entities change and to keep this feature I see some options:

  1. Removing manually the CachedVary that ASP.NET stores in the cache, assuming that the key is "a2" + query". This seems to work but I’m not sure about the reliability.

  2. Add cache keys that contain an array of the pages that have to be evicted from the cache then the key is removed o use the external cache key dependency feature in case it has it. This should be enough to emulate the key dependency we used but in a more complex way.

  3. Forget about this, put a short cache period and let them expire without worrying much about that.

  4. Do our own page caching and forget about ASP.NET output cache, not very appealing.

I’m sure there are other ways. Any tips, experiences or recommendations?

  • 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-27T01:49:54+00:00Added an answer on May 27, 2026 at 1:49 am

    I answer my own question with the solution we adopted just for the record.

    In our OutputCacheAttribute we add an empty cache object with a key that depends on the requested URL and some parameters. This will be used to invalidate a page externally.

    Then, we also add another object with a key that depends on the current request and contains the previous cacheKey.

    Finally, a static ValidationCallback is set up. The callback gets the value of the key for the current request, which is the dependency key. Then if it’s not null, gets the value of the dependency, if it’s null, the dependency has been evicted and we set the validationStatus to HttpValidationStatus.Invalid.

    Some code to illustrate:

    public override void OnResultExecuting(ResultExecutingContext filterContext)
    {
        base.OnResultExecuting(filterContext);
    
        // Build dependencies
        BuildDependencies(paramsToDepend, filterContext.Controller, this.Duration);
    }
    
    private void BuildDependencies(IEnumerable<string> paramsToDepend, ControllerBase controller, int duration)
    {
        string[] valuesToInclude = GetValuesToInclude(paramsToInclude, controller.ControllerContext);
    
        // Build the caché key for the current request
        var cacheKey = CacheKeyProvider.GetCacheKeyFor(controller, paramsToDepend);
    
        var cache = controller.ControllerContext.HttpContext.Cache;
        var cacheValue = cache.Get(cacheKey);
    
        if (cacheValue == null)
        {
            // The key is created if not exists
            Provider.Add(cacheKey, new object(), Context.CurrentDateTime.AddSeconds(duration).ToUniversalTime());
        }
    
        // Add the dependency
        Provider.Set(CachePrefix + controller.ControllerContext.HttpContext.Request.Path, cacheKey, Context.CurrentDateTime.AddSeconds(duration).ToUniversalTime());
    
        // Register callback
        controller.ControllerContext.HttpContext.Response.Cache.AddValidationCallback(new HttpCacheValidateHandler(ValidationCallback), null);
    }
    
    public static void ValidationCallback(HttpContext context, object data, ref HttpValidationStatus validationStatus)
    {
        var provider = OutputCache.Providers[OutputCache.DefaultProviderName];
    
        var dependency = provider.Get(CachePrefix + context.Request.RawUrl) as string;
    
        if (dependency == null) return;
    
        var depValue = provider.Get(dependency);
    
        // If it's null, someone has invelidated the caché (an entity was modified)
        if (depValue == null)
        {
            validationStatus = HttpValidationStatus.Invalid;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Scenario: I am in the process of refactoring one of our applications to use
We are currently in the process of refactoring our site and we have decided
I am in the process of refactoring our BI layers to make our code
We're going global. I've been tasked with refactoring our existing products to support localization.
I am refactoring a part of our legacy app which handles exporting and importing
During some recent refactoring we changed how our user avatars are stored not realizing
I'm refactoring legacy C++ system to SOA using gSoap. We have some performance issues
Here's the scenario. We use a large XML configuration file for one of our
We're in the process of redesigning the customer-facing section of our site in .NET
We currently build our Android (Java) projects using the built-in Eclipse build tools. Then

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.