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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T22:15:34+00:00 2026-05-12T22:15:34+00:00

We are working on a large legacy application and we’re redesigning the business layer

  • 0

We are working on a large legacy application and we’re redesigning the business layer and the data layer. We believe that it is a good time to redesign the way cache is handled. Are there any patterns and best practices for implementing a caching layer (or building it in the business layer)?

The only things that I can think of are to use SQL Cache Dependency (which is hard because of we’ve got a big legacy database with a lot of tables that do not always correspond to the business objects) and implementing strongly typed CacheManager class to hide the string keys and eliminate class casting problems.

Is there anything more sophisticated that we can do? Is there any way to enforce cache invalidation when performing update/delete? Should we somehow maintain a single object in the cache and retrieve list of IDs from the DB that always work with the same objects?

Basically what techniques for caching do you use in ASP.NET? Too bad we cannot use IoC containers or ORM frameworks that support cache 🙁

Edit: I am more concerned about maintainability than performance.

  • 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-12T22:15:35+00:00Added an answer on May 12, 2026 at 10:15 pm
    • Just save every queryresult to the database (with cache key: your query, value: your list of business objects)
    • Use distributed cache like memcached next to ASP.Net cache
    • Use a sophisticated cachemanager like https://github.com/enyim/memcached-providers; that can have cache-groups. Some data has to be stored for a long time, some short time. Some data has to be stored in ASP.Net cache, etc.
    • Do calls that has to be stored in the cache using a wrapper function like public T GetFromCache<T>(string key, Func<T> ifKeyNotFoundDelegate) to ensure that cache is always used the same. [1]
    • Think of when to use ASP.Net cache, and when to use distributed cache. Data that is read every request should be stored in ASP.Net, large data like search results; with a lot of different keys and data etc. should be in memcached.
    • Add versioning. Prefix all keys with a versionnumber, so you won’t get in trouble when updating your web application, and some objectcontracts change.

    Ah well, that covers most of what we do in our website (20GB memcached cluster spread over 20 servers).

    [1] By making such a function the only interface to store stuff in cache, you can achieve the following. Let’s say I want to use something from the cache, like the result from a function. Normally you would do something like

    CacheManager cm = new CacheManager(CacheGroups.Totals);
    object obj = cm.GetFromCache("function1result");
    if(obj == null)
    {
        obj = (object)DAO.Foo();
        cm.StoreInCache("function1result", obj);
    }
    return (List<MyEntity>)obj;
    

    By using a different interface you can ensure that users won’t make a mistake here.

    Like

    public T GetFromCache<T>(string key, Func<T> ifnotfound)
    {
        T obj = this.GetFromCache(key) as T;
        if(obj == default(T)) 
        { 
             obj = ifnotfound.Invoke();
             this.StoreInCache(key, obj);
        }
        return obj;
    }
    

    This ensures that

    1. We always work with the correct type
    2. That your user always work with cache the same way

    Ergo: less probable that they make a mistake. Furthermore: you get nicer, more clear, code, like:

    List<MyEntity> list = new CacheManager(CacheGroups.Total).GetFromCache<List<MyEntity>>("function1result", ()=>DAO.Foo());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a large legacy application using stateless session beans that has recently
I'm working on a very large, data-intensive legacy application. Both the code base &
I am working on a large legacy C# application and a task assigned to
I'm working with a large set of legacy data (converted from a flat-file db),
I am currently working on a very large legacy MFC MDI application. It has
I'm in a 10 person team working on a large legacy code base with
I'm working with large numbers that I can't have rounded off. Using Lua's standard
We are working with large amounts of data, all tagged in UTC (in Java).
I am working with a large Java web application from a commercial vendor. I've
I'm working on a large c++ system that is has been in development for

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.