My new blog present here.

Featured Post

Insights into Sitecore Search: A Definitive Introduction

A key component of digital experience management is effective information retrieval. A simplified approach is required for websites, applications, and platforms containing a lot of material so that consumers can easily get the data they require. This need is met by Sitecore, a well-known name in the field of digital experience platforms (DXPs), which provides powerful and comprehensive search functionality. We will travel into the realm of Sitecore Search in this article, learning about its capabilities, architecture , and the enormous value it offers both developers and end users. Introduction to Sitecore Search    A headless content discovery platform powered by AI , Sitecore Search enables you to build predictive and custom search experiences across various content sources. To extract and ...

Caching Overview (ASP.Net)

Caching Overview:

Abstract: Caching is a feature of ASP.NET that can dramatically improve the performance of your application by storing the page output or application data across HTTP requests.

This article cover:

  • What is Caching ?
  • Benefits of Caching
  • Introducing the Problems that Caching Solves
  • Types of Caching
What is caching?

  • Caching is a feature that stores data in memory, allowing incoming requests to be served from memory directly.
  • In the context of a web application, caching is used to retain pages or data across HTTP request and reuse them without the expense of recreating them.

Benefits of Caching

The following are the benefits of using Caching:

  • Faster page rendering
  • Minimization of database hits
  • Minimization of the consumption of server resources

Types of Caching

  • Page Output Caching
  • Page Fragment Caching
  • Data Caching
  • Page Output Caching:
Page level, or output caching, caches the HTML output of dynamic requests to ASP.NET Web pages. The way ASP.NET implements this is through an Output Cache engine. Each time an incoming ASP.NET page request comes in, this engine checks to see if the page being requested has a cached output entry. If it does, this cached HTML
is sent as a response; otherwise, the page is dynamically rendered, it's output is stored in the Output Cache engine.

Output caching is easy to implement. By simply using the @OuputCache page directive, ASP.NET Web pages can take advantage of this powerful technique.
The following is the complete syntax of page output caching directive

<%@ OutputCache
Duration="no of seconds“ * required field
Location="Any | Client | Downstream | Server | None"
VaryByControl="control"
VaryByCustom="browser |customstring"
VaryByHeader="headers"
VaryByParam="parameter“ * required field
%>

Example:

<%@OutputCache Duration="60" VaryByParam="none" %>
The Duration parameter specifies how long, in seconds, the HTML output of the Web page should be held in the cache.

The VaryByParam parameter is used to indicate whether any GET (QueryString) or POST (via a form submit with method="POST") parameters should be used in varying what gets cached.


  • Page Fragment Caching
In addition to output caching an entire page, ASP. Net provides Partial-Page Output
Caching, or Page Fragment Caching. Page Fragment Caching allows specific regions of pages to be cached.

Page Fragment Caching is easy to implement. By simply using the @OuputCache
page directive, ASP.NET Web pages can take advantage of this powerful technique.
The syntax looks like this:

<%@ OutputCache Duration="60" VaryByParam="none" VaryByControl="MyRadioButtonList"%>
The Duration parameter specifies how long, in seconds, the HTML output of the Web page should be held in the cache.

The VaryByParam parameter is used to indicate whether any GET (QueryString) or POST (via a form submit with method="POST") parameters should be used in varying what gets cached.

The VaryByControl parameter allows different cache entries to be made based on the values for a specified control.


  • Data Caching
ASP. Net provides a full-featured cache engine, Programmatic or data caching takes advantage of the .NET Runtime cache engine to store any data or object between responses. That is, you can store objects into a cache, similar to the storing of objects in Application scope in classic ASP.

The ASP. Net cache is private to each application and stores objects in memory. The lifetime of the cache is equivalent to the lifetime of the application.

To store a value in the cache, use syntax like this:

Cache[“myKey"] = myValue; // C#
Cache(“myKey") = myValue ' VB.NET

To retrieve a value, simply reverse the syntax like this:

myValue = Cache[“myKey"]; // C#
myValue = Cache(“myKey") ' VB.NET

Comments

Popular posts from this blog

Sitecore GraphQL Queries

Sitecore Experience Manager Cloud (XM Cloud) Building blocks

Configuring Sitecore Next.js Headless SXA Multisite App in a Sitecore Container