Sitefinity’s content management system (CMS) comes equipped with several layers of caching to ensure fast content editing and browsing experiences. The layers cover important Sitefinity objects such as media content, page HTML, configurations, client resources, and more. This blog post is designed to help you understand a little bit more about the complex world of Sitefinity caching and the different tools the platform provides users with.
What is a Cache?
First, we’ll need to understand what caching really is. In software, a ‘cache’ is a term used to define the act of fetching data or doing some calculations and storing the result for future retrieval. This results in speed improvements.
As a real-world example, say you sell a range of bags of flour and you have it all stored in a back warehouse. When a customer comes to your counter and asks for a bag, you have a delay while running to the back store to get the requested bag. To improve this, you store several of the most popular bags at your counter. By doing this, you avoid the time and effort of running to your store room and you also improve the customer’s experience.
With a website, a cache is an all-important tool for helping you keep your web page load times down, resulting in a better user experience.
Keeping every bit of data in a cache is a little impractical. Just like trying to store your entire warehouse at your counter. But we can look to improve things such as hiring a junior to keep an eye on stock levels and restock them as they are purchased – just as it happens at a supermarket. For the sake of this blog post, we’ll refer to this ‘junior’ as the cache policy/policies.
Sitefinity Website Caching
A good question to ask ourselves is, “What is the cache on our website?” The most common cache store is the computer’s memory or RAM, which stands for random access memory. RAM chips are sitting right on the motherboard of the computer near the central processing unit (CPU) and accessing this storage happens very quickly. It’s actually considered significantly faster than querying a database or hard drive.
Sitefinity, by default, uses RAM as its cache store and refers to it as an ‘InMemory’ cache. It’s very efficient but it’s also limited and bound to the amount of RAM your web servers have. In saying that, it’s not as limiting as you may first think and it shouldn’t be a constraint with a thought-out approach to your cache policy.
Another type of cache is a ‘Distributed’ cache. This is a specialist application that is run on its own server. Sitefinity supports two distributed cache applications. Redis and AWSDynamoDB. They’re both specially designed for redundant storage and very fast network data retrieval.
You should consider a Distributed cache when you have multiple web servers serving your clients. Save you have three web servers and a page has a request which takes three seconds to get data that is 5MB in size. Using an InMemory cache means that each web server will need to store that same information. As a result, three customers will have to suffer that extra three-second delay on that web page as the web server gets that data before it’s stored locally and we will be using, overall, 15MB of RAM to store the data. You may even consider the CPU of your web server and database having to do the same work three times, which may be an issue if you are paying by CPU cycles.
When using a Distributed cache, it means that the first web server will suffer the three seconds but the other two web servers won’t as they will be able to retrieve that data stored from the first web server from the Distributed cache. Also, the CPU work at the web server and database will only be done once as well.Sitefinity’s online documentation can help you decide which type of caching configuration is right for your website.
Sitefinity InMemory Cache Tools
For the remainder of this blog post, we’ll be going through the different InMemory caching tools that come out-of-the-box with the Sitefinity platform.
The L2 Cache
Sitefinity provides a built-in L2 Cache. This helps by storing database result sets in the cache without us needing to do anything.
The next, and probably most important, cache tool Sitefinity provides us with is the Output Cache. This cache stores the final HTML output of a page so that it can be sent straight to the visitor avoiding all page-building logic.
When setting up an output cache, we can specify how long the page should be cached along with several other options. We are also able to create multiple output cache policies and apply these accordingly to different pages for the best results.
One consideration with page caching will be pages that are personalized. We may want different visitors to see different things on the same page. If you are using Sitefinity’s Personalization Module, it’s all considered out-of-the-box.
If you’re not using the module, but have some personalization requirements, there are still options to help you out. You have the ability to store multiple versions of the same page in the output cache by intercepting the request and making your own decisions. As an example, you want to show special offers to all people that are in the VIP role. When the request comes in, you can check the user’s role and send them to a different version of that cached page.
Sitefinity’s documentation site has more detailed information on how to configure the cache settings.
You can read a lot about your client cache options on the Sitefinity documentation site.
When creating your site, it’s not uncommon to be doing some of your own data queryings, be it from your Sitefinity database, another internal database, or even a third-party web service.
When doing this, you can also store the results in the global Sitefinity application cache under unique names. You have the ability to determine how long that data stays in the cache as well as functions to flush or refresh it.
A Dirty Cache
The term ‘dirty cache’ is when the cache is holding data that no longer matches what’s in your database. For example, when we edit and publish a web page, we want those changes to be seen by our visitors straight away. We don’t want to have to wait for the page cache time to expire.
Sitefinity has a ‘Cache Dependency’ concept. When you add the ‘News’ widget to a page, Sitefinity will register that that page has a dependency on the News module. If you update news items, Sitefinity will look up those pages and clear the output cache so that the next request will get the latest version of the news data.
When we develop custom widgets, Sitefinity provides us with interfaces and code to associate data modules to replicate that same behavior. For any custom application caches created, we can look to use data events or webhooks to be notified when changes are made. This allows us to clear named caches, ensuring they become refreshed.
Sitefinity supports one more type of cache and that is the use of third-party CDNs (content delivery networks). A CDN is a distributed service of servers across the globe allowing you to push and store your files (for example, images) closer to the visitors accessing them, improving the download time for the page.
Think about a web server hosted in Texas and accessed by visitors in France. Rather than waiting for 20 images to travel over the Atlantic Ocean, they are pulled from a nearby CDN server located in Paris.
You can read more about Sitefinity’s CDNs on the documentation page.
Planning Your Cache Policy
With a Sitefinity site, you should take some time to plan and understand what caching solutions you are using. They are a great tool to help improve the performance of your website. They also help others understand what is going on (I am thinking of your testers here), such as when a change is made to data but the result is not reflected on a web page.
A good caching policy doesn’t need to be complicated for it to get some fantastic results for your website.
As a Progress Titanium partner, Americaneagle.com has extensive experience building solutions on the Sitefinity platform. Our team holds the knowledge necessary to create you a dynamic digital experience that leverages the full suite of tools available on the platform. To speak with aSitefinity expert, contact us today.