• Home
  • About
  • Contact
  • ado.net
  • angular
  • c#.net
  • design patterns
  • linq
  • mvc
  • .net core
    • .Net Core MVC
    • Blazor Tutorials
  • sql
  • web api
  • dotnet
    • SOLID Principles
    • Entity Framework
    • C#.NET Programs and Algorithms
  • Others
    • C# Interview Questions
    • SQL Server Questions
    • ASP.NET Questions
    • MVC Questions
    • Web API Questions
    • .Net Core Questions
    • Data Structures and Algorithms

ASP.NET MVC Caching Interview Questions

In this article, I am going to discuss the Most Frequently asked ASP.NET MVC Caching Interview Questions and Answers. Please read our previous article where we discussed the most frequently asked Filters Interview Questions in ASP.NET MVC Application with Answers.

What is Caching?
Caching is the most important aspect of the high-performance web application. Caching provides a way of storing frequently accessed data and reusing that data. Practically, this is an effective way of improving the web application’s performance.

When to use Caching in ASP.NET MVC Application?
  • Use caching for contents that are accessed frequently.
  • Avoid caching for contents that are unique per user.
  • Avoid caching for contents that are accessed infrequently/rarely.
  • Use the VaryByCustom function to cache multiple versions of a page based on customization aspects of the request such as cookies, role, theme, browser, and so on.
  • For efficient caching use a 64-bit version of Windows Server and SQL Server.
  • For database caching make sure your database server has sufficient RAM otherwise, it may degrade the performance.
  • For caching of dynamic contents that change frequently, define a short cache–expiration time rather than disabling caching.
What are the advantages of caching in ASP.NET MVC Application?
We are getting the following advantages of using caching:
  • Reduce hosting server round-trips
  • When content is cached at the client or in proxies, it causes the minimum request to the server.
  • Reduce database server round-trips
  • When content is cached at the web server, it can eliminate the database request.
  • Reduce network traffic
  • When content is cached at the client-side, it also reduces the network traffic.
  • Avoid time-consumption for regenerating reusable content
  • When reusable content is cached, it avoids the time consumption for regenerating reusable content.
  • Improve performance
  • Since cached content reduces round-trips, network traffic and avoids time consumption for regenerating reusable content which causes a boost in the performance.
What is the Output Caching in ASP.NET MVC Application?
The OutputCache filter allows you to cache the data that is the output of an action method. By default, this attribute filter caches the data until 60 seconds. After 60 sec, ASP.NET MVC will execute the action method again and cache the output again.
ASP.NET MVC Caching Interview Questions and Answers

The output of the Index() action method will be cached for 20 seconds. If you will not define the duration, it will cache it for by default cache duration 60 sec.

Output Caching Location
By default, content is cached in three locations: the webserver, any proxy servers, and the user’s browser. You can control the content’s cached location by changing the location parameter of the OutputCache attribute to any of the following values: Any, Client, Downstream, Server, None, or ServerAndClient.

By default, the location parameter has the value and which is appropriate for most of the scenarios. But sometimes there are scenarios when you required more control over the cached data.

How to allow users to submit HTML tags in ASP.NET MVC?
By default, ASP.NET MVC doesn’t allow a user to submit HTML for avoiding the Cross-Site Scripting attack on your application. You can achieve it by using the ValidateInput attribute and AllowHtml attribute. The ValidateInput attribute can enable or disable input validation at the controller level or at any action method.
[ValidateInput(false)]
public class HomeController : Controller
{
    public ActionResult AddArticle()
    {
        return View();
    }
}

The ValidateInput attribute allows the Html input for all the properties and that is unsafe. Since you have enabled Html input for only one-two properties then how to do this. To allow Html input for a single property, you should use the AllowHtml attribute.
public class BlogModel
{
    [Required]
    [Display(Name = "Title")]
    public string Title { get; set; }
    [AllowHtml]
    [Required]
    [Display(Name = "Description")]
    public string Description { get; set; }
}

What is loose coupling and how is it possible in MVC Design Pattern?
One of the most important features of the MVC design pattern is that it enables separation of concerns. Hence you can make your application’s components independent as much as possible. This is known as loose coupling and it makes testing and maintenance of our application easier. Using Dependency Injection you can make your application’s components more loosely coupled.

What is Test-Driven Development (TDD)?
TDD is a methodology that says; write your tests first before you write your code. In TDD, tests drive your application design and development cycles. You do not do the check-in of your code into source control until your entire unit tests pass.

What are the commonly used tool for Unit Testing in ASP.NET MVC?
ASP.NET MVC has been designed for testability without dependencies on the IIS server, on a database, or on external classes. There are following popular tools for ASP.NET MVC testing:
  • NUnit – This is the most popular unit testing framework for Microsoft .NET. Its syntax is relatively simple and easy to use. It comes with a test runner GUI and a command-line utility. NUnit is also available as a NuGet package for download.
  • xUnit.NET – This provides a way to run automated unit tests. It is simple, easily extended, and has a very clean syntax.
  • Ninject – This provides a way to wire up classes in your application.
  • Moq – This provides a framework for mocking interfaces and classes during testing.
In this article, I try to explain the most frequently asked ASP.NET MVC Caching Interview Questions and Answers. I hope this article will help you with your needs. I would like to have your feedback. Please post your feedback, question, or comments about this article.

0 comments:

Post a Comment

If you like this website, please share with your friends on Facebook, Twitter, LinkedIn.

Join us on Telegram

Loved Our Blog Posts? Subscribe To Get Updates Directly To Your Inbox

Like us on Facebook

Popular Posts

  • What is Dependency Injection(DI)
    Hi friends! Today we are going to learn about Dependency Injection and in our last session we have come across Static classes and where it s...
  • Navigation Menus in ASP.NET Core
    In this article, I am going to discuss how to create Responsive Navigation Menus in ASP.NET Core Application using bootstrap and JQuery. P...
  • What is Abstract Class and When we should use Abstract Class
    Hi friends! In our previous sessions we have seen  Difference Between Class and Struct . And in our last session  we learnt Usability of Sec...
  • Refresh Token in Web API
    In this article, I am going to discuss how to implement Refresh Token in Web API by validating the clients, as well as I, will also discus...
  • HTTP Client Message Handler in Web API
    In this article, I am going to discuss HTTP Client Message Handler in Web API with real-time examples. As we already discussed in HTTP Mes...
  • Anonymous Types in C#
    Hi friends! Today we are going to learn about Anonymous Types in C#. Let's start with the Introduction Anonymous is a type that does...
  • ASP.NET Web API Basic Authentication
    In this article, I am going to discuss how to implement the ASP.NET Web API Basic Authentication step by step with an example. Please read...

Blog Archive

Contact Form

Name

Email *

Message *

Tags

.Net .Net Core .Net Core MVC Algorithm Angular Anonymous Types Asp.Net Asp.Net MVC Blazor C# Data Structure Database Design Patterns Entity Framework Entity Framework Core Filters Interview Question Management Studio Programming Programs SQL Server SSMS Web API

Copyright © C# Techtics | All Right Reserved.

Protected by Copyscape