Introduction
Output caching is not a new concept. There is a variety of project that people try to implement output caching, but how to do it in EpiServer?
What is Output caching?
The main purpose of using Output Caching is to dramatically improve the performance of an ASP.NET MVC Application. It enables us to cache the content returned by any controller method so that the same content does not need to be generated each time the same controller method is invoked.
Why using output caching?
Output Caching has huge advantages, such as:
*Reduces the load on the server because there is no need to generate the results again
* Reduces the load on DB (same reason)
* Faster response
How it is done on MVC?
OutputCacheAttribute class has been implemented in System.Web.Mvc class and can easily being used simply by decorating the Controller with [OutputCache]. There are different variations for using it, which I am not going to discuss now, but you can read more in here.
What is the problem? Lets use it on EpiServer.
- You have a page on your CMS and someone tries to view it for the first time. The MVC engine will try to generate the results and then save in in cache.
A second later, another person requests the same exact page. As you've guessed the MVC will receive the request and since it has it on its cache, it will respond with the same exact results.
- On the next step the editor change something on the page and publish it, but s(he) will see the same exact results as before since MVC doen't know about the change and will still return the same response. This also happens for the next people whom request the same page.
So to summarize we have 2 big problem:
1- content should not be cached for the editors
2- After publishing a page the old cache should be invalidate and the whole process should go through
How to fix it?
To fix the problems by yourself you need a lot of knowledge about EPiServer and you need some time to implement it. Luckily EPiServer has implemented their own ContentOutputCacheAttribute that will handle those for you :)
Simply add ContentOutputCache on top of your action
public class MyPageController : PageController<PageType>
{
[ContentOutputCache(Duration = 3600, VaryByCustom = "*")]
public ActionResult Index(StartPage currentPage)
{
...
}
}
Handle your GetVaryByCustomString in your Global.asax and you are good to go
public class EPiServerApplication : EPiServer.Global
{
public override string GetVaryByCustomString(HttpContext context, string custom)
{
....
}
}
What to put into the GetVaryByCustomString depends on your setup, but one simple example could be returning the AbsoluteUri of the page. This way, different pages will differ, language versions will be handled automatically (since the AbsoluteUri will be different regardless of your routing config) but be aware that the personalization will not work since the AbsoluteUri is the same for all different users.
public override string GetVaryByCustomString(HttpContext context, string custom)
{
return context.Request.Url.AbsoluteUri;
}
****Very Important!!!!
ContentOutputCache will not work, unless you have the httpCacheExpiration in your web.config.
Simply go to your webconfig>
configuration>episerver>applicationSettings and make sure that it has properties for httpCacheability and httpCacheExpiration.
It should be something like this:
It should be something like this:
<configuration>
...
<episerver>
<applicationSettings httpCacheability="Public" httpCacheExpiration="0:10:00" .... />
</episerver>
....
</configuration>
There are a couple of issues that have been found with this approach. 1. It only works on a page level, meaning that although it's clever enough to invalidate when blocks change you have no DonutHole style cache control on a block level. 2. It doesn't play well with visitor groups out of the box so following an article such as https://www.david-tec.com/2014/03/Enabling-output-caching-on-an-EPiServer-site-that-uses-Visitor-Groups/ would be good. It's a good attribute but it's good for people to be aware of it's limitations
ReplyDeleteHi Scott,
DeleteI agree. David's approach is very good and of course needs a bit of updating (since VisitorGroupRole.GetRepository() is deprecated :) ).
I will update my post as soon as I've found some time ;P
adıyaman
ReplyDeletesakarya
yalova
tekirdağ
amasya
PAV3
görüntülü.show
ReplyDeletewhatsapp ücretli show
73U
https://titandijital.com.tr/
ReplyDeletenevşehir parça eşya taşıma
bolu parça eşya taşıma
batman parça eşya taşıma
bayburt parça eşya taşıma
YS5H4D
antalya evden eve nakliyat
ReplyDeleteankara evden eve nakliyat
bursa evden eve nakliyat
yalova evden eve nakliyat
gümüşhane evden eve nakliyat
4Y25
ordu evden eve nakliyat
ReplyDeletebursa evden eve nakliyat
konya evden eve nakliyat
osmaniye evden eve nakliyat
bitlis evden eve nakliyat
6ZU6
8FC9E
ReplyDeleteAydın Şehir İçi Nakliyat
Düzce Şehir İçi Nakliyat
Adıyaman Parça Eşya Taşıma
Çerkezköy Marangoz
Giresun Lojistik
Sivas Şehirler Arası Nakliyat
Keçiören Parke Ustası
Tekirdağ Şehirler Arası Nakliyat
Antalya Şehirler Arası Nakliyat
9FBC5
ReplyDeleteWabi Coin Hangi Borsada
Batman Şehir İçi Nakliyat
Kütahya Parça Eşya Taşıma
Mith Coin Hangi Borsada
Bilecik Şehir İçi Nakliyat
Diyarbakır Lojistik
Maraş Lojistik
Loop Network Coin Hangi Borsada
Bartın Parça Eşya Taşıma
9BAF5
ReplyDeleteZonguldak Parça Eşya Taşıma
Ünye Oto Lastik
Etlik Fayans Ustası
Kilis Şehirler Arası Nakliyat
Silivri Cam Balkon
Bayburt Evden Eve Nakliyat
Maraş Evden Eve Nakliyat
İzmir Evden Eve Nakliyat
İzmir Lojistik
A70B6
ReplyDeletemuhabbet sohbet
bursa mobil sohbet sitesi
eskişehir görüntülü sohbet kızlarla
çankırı rastgele görüntülü sohbet
aksaray bedava görüntülü sohbet sitesi
bingöl yabancı canlı sohbet
uşak telefonda canlı sohbet
erzincan telefonda canlı sohbet
mobil sohbet sitesi
14ED9
ReplyDeleteAğrı Canli Goruntulu Sohbet Siteleri
antep rastgele görüntülü sohbet uygulamaları
Afyon Telefonda Kadınlarla Sohbet
Burdur Canlı Sohbet Odaları
ücretsiz sohbet siteleri
adana telefonda kızlarla sohbet
Diyarbakır Canli Goruntulu Sohbet Siteleri
Siirt Kızlarla Canlı Sohbet
mardin sohbet odaları
CD84E
ReplyDeleteNevşehir Rastgele Sohbet Uygulaması
canlı görüntülü sohbet odaları
adıyaman telefonda görüntülü sohbet
Antalya Seslı Sohbet Sıtelerı
görüntülü sohbet siteleri
parasız görüntülü sohbet
kastamonu muhabbet sohbet
Mardin Rastgele Görüntülü Sohbet Uygulamaları
aydın rastgele görüntülü sohbet
4F068
ReplyDeleteamasya ücretsiz sohbet
isparta en iyi ücretsiz sohbet uygulamaları
van ücretsiz sohbet sitesi
rastgele görüntülü sohbet
canli goruntulu sohbet siteleri
nanytoo sohbet
kırklareli mobil sohbet odaları
kırşehir canli goruntulu sohbet siteleri
Şırnak Bedava Sohbet Odaları
DC448
ReplyDeleteReferans Kimliği Nedir
Threads Yeniden Paylaş Hilesi
Threads Beğeni Hilesi
Binance'de Kaldıraç Var mı
Twitter Takipçi Hilesi
Paribu Borsası Güvenilir mi
Soundcloud Reposts Satın Al
Sweat Coin Hangi Borsada
Threads Takipçi Satın Al
5FE29
ReplyDeleteKripto Para Üretme Siteleri
Mexc Borsası Güvenilir mi
Discord Sunucu Üyesi Hilesi
Telegram Abone Hilesi
Big Wolf Coin Hangi Borsada
Youtube Abone Satın Al
Ceek Coin Hangi Borsada
Telegram Görüntüleme Satın Al
Pitbull Coin Hangi Borsada
8E4C6
ReplyDeleteHamster Coin Hangi Borsada
Tiktok Beğeni Hilesi
Hexa Coin Hangi Borsada
Referans Kimliği Nedir
Clubhouse Takipçi Satın Al
Facebook Takipçi Satın Al
Tiktok İzlenme Hilesi
Coin Nasıl Oynanır
Likee App Beğeni Satın Al
74CBA
ReplyDeleteBitcoin Mining Nasıl Yapılır
Meta Coin Hangi Borsada
Threads Yeniden Paylaş Satın Al
Twitch İzlenme Hilesi
Coin Madenciliği Nasıl Yapılır
Instagram Takipçi Hilesi
Raca Coin Hangi Borsada
Binance Sahibi Kim
Binance Referans Kodu
F26F180442
ReplyDeletegörüntülü şov