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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T07:30:43+00:00 2026-05-31T07:30:43+00:00

I have an application where each user can choose a custom layout. The layouts

  • 0

I have an application where each user can choose a custom layout. The layouts can be different and it’s not just css styles but html as well.

I know that mvc would cache the layout, but having so many layouts I doubt it would fit in cache. So what would it be better to save templates in DB or on the disk?

FYI: DB that I’m using is MongoDB.

  • 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-31T07:30:45+00:00Added an answer on May 31, 2026 at 7:30 am

    I would save the layouts on disk because at the moment I don’t see any advantage in a database (unless you do). But one thing that is worth mentioning is that you can create a class derived from OutputCacheAttribute and have your saved result depend on the layout you’re using.

    Does the layout depend on user? You could use the VaryByCustom property to have it vary by user.

    EDIT

    Are your users allowed to change layouts dinamically? If yes, you should also have a guid associated to your users change it each time the layouts change so you return on your VaryByCustom method:

    return string.Format("User-{0}-{1}", user.Id, user.LayoutUpdateGuid);
    

    See the meaning of this? This way, when a user changes the layouts, they will see their pages updated immediately.

    How to apply the VaryByCustom attribute in your situation

    In your action method, you may use:

    [OutputCache(Duration = 3600, VaryByCustom = "UserLayouts")]
    public ActionResult Details(string param)
    {
       // Returning the view
    }
    

    Then, in your VaryByCustom method in your Global.asax.cs file:

    protected override string VaryByCustom(string custom)
    {
      switch (custom)
      {
        case "UserLayouts":
          //// Here you fetch your user details so you can return a unique
          //// string for each user and "publishing cycle" 
          //// Also, I strongly suggest you cache this user object and expire it
          //// whenever the user is changed (e.g. when the LayoutUpdateGuid is
          //// changed) so you achieve maximum speed and not defeat the purpose
          //// of using output cache.
          return string.Format("User-{0}-{1}", user.Id, user.LayoutUpdateGuid);
        break;
      }
    }
    

    The missing piece

    The missing piece here is that you need to store a value that I called LayoutUpdateGuid (I’m sure you’ll find a better name) and change that value whenever a user changes his layouts => this will lead to a different string being returned by the VaryByCustom(string) method in the Global.asasx.cs which in turn will force your action method to run again and return the result with the updated layout.

    Makes sense to you?

    Note: I can’t test the specific code I wrote here, but I am sure (apart from typos) it is correct.

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

Sidebar

Related Questions

I have an application where for each object the user can specify his own
I have a web application with users and their documents. Each user can have
I am building a multi-user web application. Each user can have their own site
I have a rails application where each user has a separate database. (taking Joel
I have an application that has many different types of objects that each persist
I have a custom MVC application/framework where each action is a function inside of
I have an application in which the user will choose to do a number
There are several packages in my application that user can select each one according
I have a list of users on my php application (using codeigniter). Each user
I have simple application, that shows list of many items, where user can display

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.