Caching and caching dependencies explained in Kentico CMS

Slides:



Advertisements
Similar presentations
Go Live! Launching your MOSS Publishing site DEV435 Spencer Harbar.
Advertisements

Built-in Kentico CMS UI Controls
© 2012 Entrinsik, Inc. Informer Administration Exploring the system menu and functions PRESENTER: Jason Vorenkamp| Informer Software Engineer| March 2012.
Business Development Suit Presented by Thomas Mathews.
Master Pages, User Controls, Site Maps, Localization Svetlin Nakov Telerik Corporation
1 Trieste, April 17 th 2008Lucio Zambon Electronic Graphic Interface for Global Archiving Technology: PHP, MySQL, JavaScript, JPGraph, etc Development.
CHAPTER 15 WEBPAGE OPTIMIZATION. LEARNING OBJECTIVES How to test your web-page performance How browser and server interactions impact performance What.
ASP.NET Best Practices Dawit Wubshet Park University.
Kentico CMS 5.5 R2 What’s New. Highlights Intranet Solution Document management package – WebDAV support – Project & task management – Document libraries.
Universal event handling for components in Kentico CMS
1 Configuring Internet- related services (April 22, 2015) © Abdou Illia, Spring 2015.
Maxim Zhvirblya EPAM Systems © 2013 Or make MSSQL breathe easily RBS and Blob Cache in SharePoint 2013.
Turners SharePoint Web Site How we did it. 2 Page Anatomy Custom Search Web Part Custom Search Web Part Data Form Web Parts Content Query Web Part HTML.
Web Development in Microsoft Visual Studio Slide 2 Lecture Overview Introduce Visual Studio 2013 Create a first ASP.NET application.
Chapter 9 Chapter 9: Managing Groups, Folders, Files, and Object Security.
1 Chapter 12 Working With Access 2000 on the Internet.
1 of 6 This document is for informational purposes only. MICROSOFT MAKES NO WARRANTIES, EXPRESS OR IMPLIED, IN THIS DOCUMENT. © 2007 Microsoft Corporation.
XP Tutorial 9 New Perspectives on JavaScript, Comprehensive1 Working with Cookies Managing Data in a Web Site Using JavaScript Cookies.
1 of 7 This document is for informational purposes only. MICROSOFT MAKES NO WARRANTIES, EXPRESS OR IMPLIED, IN THIS DOCUMENT. © 2007 Microsoft Corporation.
1 of 5 This document is for informational purposes only. MICROSOFT MAKES NO WARRANTIES, EXPRESS OR IMPLIED, IN THIS DOCUMENT. © 2006 Microsoft Corporation.
Handling Security Threats in Kentico CMS Karol Jarkovsky Sr. Solution Architect Kentico Software
1 Chapter Overview Creating User and Computer Objects Maintaining User Accounts Creating User Profiles.
Christopher M. Pascucci Basic Structural Concepts of.NET Browser – Server Interaction.
Performance Mistakes In Kentico 7/18/2012Miro Remias, Solution Architect.
Form Handling, Validation and Functions. Form Handling Forms are a graphical user interfaces (GUIs) that enables the interaction between users and servers.
JavaScript & jQuery the missing manual Chapter 11

CSC 2720 Building Web Applications Cookies, URL-Rewriting, Hidden Fields and Session Management.
Real World Examples – Part II 7/26/2013Miro Remias, Sr. Solution Architect.
Beginning Web Site Development Module 1 – Dynamic Web Site Development Fundamentals of building dynamic Web sites with ASP.NET 2.0 and C# Version.
Building Highly Scalable Websites Karol Jarkovsky Sr. Solution Architect
JavaScript, Fourth Edition Chapter 12 Updating Web Pages with AJAX.
5 Chapter Five Web Servers. 5 Chapter Objectives Learn about the Microsoft Personal Web Server Software Learn how to improve Web site performance Learn.
Copyright 2000 eMation SECURITY - Controlling Data Access with
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Environment.
LiveCycle Data Services Introduction Part 2. Part 2? This is the second in our series on LiveCycle Data Services. If you missed our first presentation,
Database-Driven Web Sites, Second Edition1 Chapter 5 WEB SERVERS.
Computer Emergency Notification System (CENS)
Caching Chapter 12. Caching For high-performance apps Caching: storing frequently-used items in memory –Accessed more quickly Cached Web Form bypasses:
Module 10 Administering and Configuring SharePoint Search.
Christopher M. Pascucci Basic Structural Concepts of.NET Managing State & Scope.
Session and Cookie Management in.Net Sandeep Kiran Shiva UIN:
ASP.NET Caching - Pradeepa Chandramohan. What is Caching? Storing data in memory for quick access. In Web Application environment, data that is cached.
® IBM Software Group © 2007 IBM Corporation Best Practices for Session Management
Chapter 10 Chapter 10: Managing the Distributed File System, Disk Quotas, and Software Installation.
ASP. What is ASP? ASP stands for Active Server Pages ASP is a Microsoft Technology ASP is a program that runs inside IIS IIS stands for Internet Information.
LANDESK SOFTWARE CONFIDENTIAL Tips and Tricks with Filters Jenny Lardh.
Web Design and Development. World Wide Web  World Wide Web (WWW or W3), collection of globally distributed text and multimedia documents and files 
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Fundamentals of Web DevelopmentRandy Connolly and Ricardo HoarFundamentals of Web DevelopmentRandy Connolly and Ricardo Hoar Fundamentals of Web DevelopmentRandy.
ASP-2-1 SERVER AND CLIENT SIDE SCRITPING Colorado Technical University IT420 Tim Peterson.
Module 6: Administering Reporting Services. Overview Server Administration Performance and Reliability Monitoring Database Administration Security Administration.
CHAPTER 7 LESSON C Creating Database Reports. Lesson C Objectives  Display image data in a report  Manually create queries and data links  Create summary.
Session 11: Cookies, Sessions ans Security iNET Academy Open Source Web Development.
Developer Exam Preparation Thom Robbins Bryan Soltis
Using the Kentico CMS API Thom Robbins Bryan Soltis
Introduction to ASP.NET, Second Edition2 Chapter Objectives.
Kentico CMS Performance Optimization Implementation at Newsmax - Ayush Chaturvedi.
IBM Software Group © 2008 IBM Corporation Tivoli Provisioning Manager Beta Program Web Replay Intro and Lab September, 2008 Robert Uthe.
Cofax Scalability Document Version Scaling Cofax in General The scalability of Cofax is directly related to the system software, hardware and network.
Enhance Your Page Load Speed And Improve Traffic.
Performance optimization and caching in Kentico CMS Martin Hejtmanek (CTO), Webinar 9/16/2009.
ArcGIS for Server Security: Advanced
Managing State Chapter 13.
Caching Data in ASP.NET MVC
Data Virtualization Tutorial… CORS and CIS
Web Caching? Web Caching:.
Utilization of Azure CDN for the large file distribution
The Request & Response object
Exploring the Power of EPDM Tasks - Working with and Developing Tasks in EPDM By: Marc Young XLM Solutions
Presentation transcript:

Caching and caching dependencies explained in Kentico CMS Boris Pocatko Solution Architect Kentico Software borisp@kentico.com

Agenda Problem Describing different caching mechanisms Demo for cache dependencies API caching and additional info

Problem Caching is a interesting topic useful for speeding up your pages and understanding all cache types in Kentico can be a challenge. Examples What to do if I have dynamic content. What to do with static content How to delete the cache on specific scenarios How to cache data in code Caching in macros

Types of caching mechanisms Client cache (browser) IIS cache (Kernel cache blog post) Output cache (Kentico) File system cache (Kentico) Partial cache (Kentico/.NET) Content cache (Kentico) Custom code cache (Kentico API)

Data retrieval (schema) Request Browser Client cache (files) Client IIS Kernel cache (html) Server cache (files) Output cache (html) File system cache (html) Server Kentico Partial cache (html) Content cache (data) Custom code cache (data) Code (Page_Load, Init …) Database

Kentico file cache The system caches files for faster response times (images, JavaScript files, style sheet files and other types of files) Two types of file caches: Client-side – stored by the browser on the side of the client Server-side – stored on the server itself, in it’s memory

Kentico client-side cache uses HTTP request headers to control file caching in client browsers and intermediate network caches Is set in SiteManager > Settings > System > Performance > Client cache (minutes) (this specifies basically, that the client browser doesn’t have to get new content until the given time expires) Data saved on the browser The ideal solution, cache revalidation needs to be implemented Must revalidate, Etag, Last-Modified, Expires, Cache-Control values influence how the browser revalidates the content You can include the Must revalidate attribute with a setting in SiteManager > Settings > System > Performance > Must revalidate The Must revalidate attribute is interpreted by different browsers in different ways (blog) The revalidation needs an additional request

Kentico client-side files cache

Kentico client-side files cache

Kentico client-side files cache

Kentico client-side files cache

IIS Kernel cache IIS caching is the second best caching option The request isn’t processed by the Kentico at all, IIS is returning the content Configured on IIS (link) More details available in our webinar

Kentico server-side files cache The same content is stored as in the client cache Stores files in the application's memory, so that the CMS doesn't have to access the database or file system every time a user requests an image or other file. Site Manager > Settings -> System -> Performance > Cache files (minutes) setting The system always caches files for at least one minute to prevent the application from overloading in case of DoS attacks. Make sure not too big files are cached, so you don’t run out of memory (set the Maximum file size to cache setting) You can redirect files to the disk, if you have the files stored in the file system (not only in DB), so you allow to process it via IIS (the request uses redirection to the physical file), with this property disabled, they are process directly via our files processing script (if you store files in the file system and don’t have this setting checked, the requests are still processed with our custom script and not with IIS)

Kentico cache in general Every cached item in Kentico (it doesn’t matter if it’s the output cache, partial, data cache, file system cache) has a key according to which the data is cached and retrieved. This key consists of variables, which can cause different data to be cached. Examples of these variables are: protocol, url, username, sitename, lang, browser, cookielevel, deviceprofile This key is used for retrieval of the cache If a cache item with such a key doesn’t exist, the output is generated from scratch Data Key

Kentico output cache Enabled in Site Manager > Settings > System > Performance > Enable output caching. Configured on individual pages (Properties > General > Use output cache and Cache minutes) Saves the generated output HTML of whole pages to the memory (by default) The most effective way how to speed up your pages Not usable with pages with very frequently changing content (dynamic content, such as random products web part), but great for static pages where the content is updated once in a while (e.g. once an hour or day) You can use cache dependencies with the Output cache dependencies web part You can use substitution macros for displaying dynamic content on a cached page

Kentico output cache (substitution macros) Client Substitution macros (“{~myexpression~}”) are developed the same way as custom macros, it’s up to you what content is replaced for them Kentico Output filter Replace substitution macros Output cache (html)

Kentico output cache (substitution macros)

Kentico file system output cache Prerequisite: Globally enabled in System > Performance > Output caching > Cache output in file system (minutes) Configured additionally individual pages (same place as Output cache) Saves the output HTML to the file system Useful during site restarts, when the cache from the server memory isn’t available

Kentico partial cache Partial cache is used when you are not able to use full page (output) caching (e.g. a lot of dynamic content on your page) This type of caching can be used to cache the HTML of the page at least partially Ideally, resource intensive components should be cached (e.g. repeaters with nested controls) We are utilizing the PartialCachingControl .NET object Set on the web part directly CMSPartialCacheItems - List of the cache key items for partial caching. Default value is "username;sitename;lang" cache dependencies Editable web parts, have additionally the dependency to the current document Default cache dependency is based on instance GUID of the web part

Kentico partial cache - By default the cached content is flushed once you change the settings of the web part

Kentico cache dependencies They can be used on different cached objects: Full page cache Partial cache Custom cache Content cache Macro cache Cache dependencies are basically dummy cache keys pointing to other cached content If the content, which is listed in the dummy key, is changed, the associated cache (e.g. the cache of a web part) is flushed

Kentico cache dependencies

Kentico cache dependencies There are two main object types used in cache dependencies: Document (TreeNode) Any object (except document) How to set up custom table dependencies is described here

Kentico content cache You can set it up on two levels - either on a global level, which influences a whole site, or you can enable content cache for individual instances of web parts and controls. Globally enabled in Site Manager > Settings > System > Performance > Cache content (minutes)  Cache minutes property on web parts: You can specify a custom Cache item name, which will allow you to share the cached data between web parts. It’s used instead of the cache Key string of variables Don’t forget that properties can contain macros = dynamic cache item names based on the context (e.g query string values)

Kentico content cache

Kentico custom code cache using CMS.SiteProvider; using CMS.GlobalHelper;   private void CachingExample() {   DataSet data = null;   // Cache the data for 10 minutes with key "mykey"   using (CachedSection<DataSet> cs = new CachedSection<DataSet>(ref data, 10, true, null, "mykey"))    {       if (cs.LoadData)        { // Get data from database            data = UserInfoProvider.GetAllUsers(); // Don’t configure cache settings if not necessary (e.g. condition set to false, cache minutes = 0) if (cs.Cached) {  // Cache dependency            cs.CacheDependency = CacheHelper.GetCacheDependency("node|corporatesite|/news|childnodes");         } cs.Data = data; // Save data to cache }    }

Kentico custom code cache Clearing the cache manually (not with help of build in dependencies) protected void CreateTouchableCacheItem_Click(object sender, EventArgs e) { string data = ""; //caching using (CachedSection<String> cs = new CachedSection<String>(ref data, 15, true, null, "MyNewKey")) if (cs.LoadData) // Get from database or set it differently (here only assigned for presentation purposes) data = "MyData"; cs.CacheDependency = CacheHelper.GetCacheDependency("touchthis".ToLower()); cs.Data = data; } protected void ToucheItem_Click(object sender, EventArgs e) CacheHelper.TouchKey("touchthis");

Kentico page info cache The PageInfo object contains some common properties of documents, which are used quite often (e.g. DocumentName, DocumentID, NodeAliasPath…) To reduce overhead these values are cached by default Kentico sets automatic cache dependencies, so if data related to this object is updated, the cache is flushed Contains most of the View_CMS_Tree_Joined properties (Document and Node fields) Use it as often as possible (custom code, macros): CMS.CMSHelper.CMSContext.CurrentPageInfo.DocumentName {% CurrentPageInfo.DocumentName%}

Caching in macros You can specify caching dependencies, conditional caching and caching time also directly in macros {%CMSContext.Current.Documents["/News"].Children.WithAllData.ApplyTransformation("CMS.News.default_macro","","").Cache(10, true, "my_macro_html", "", GetCacheDependency("node|corporatesite|/news|childnodes")) #%}

Kentico cache dependencies DEMO – caching

Kentico cache debug Cache items (Site Manager > Administration > System > Debug) are listed by default, no additional setup is needed For cache access debug you need to enable the setting in Site Manager > Settings > System > Debug Use both of them if developing custom controls with caching or custom caching dependencies Missing Partial cache debug (we are using the .NET implementation)

Additional notes The system sometimes caches data separately for each logged-in user. This means that even though some data is cached for one user, when another user requests the same data, the system retrieves the data from the database and stores it in the cache as another cache item.  Don’t over-cache Check the Site Manager > Administration > System for general cache statistics Cache item name (web part properties), Cache key, CacheItemNameParts (API) are synonyms

Interesting web.config keys CMSAlwaysCacheResources (true) -Enables/disables client caching of (minifiable) resources. Please note that caching on the client side is not done at all if the Client cache (minutes) setting is disabled (set to 0) in Site Manager -> Settings -> System -> Performance. CMSPhysicalFilesCacheMinutes (10080) - Determines expiration time in minutes that should be set for the physical files in the client cache, e.g. stylesheets not managed via the CMS. CMSAzureCachePath - Specifies a folder on a local disk where files requested from the storage account will be cached. This helps minimize the amount of blob storage operations, which saves time and resources.  Do not use this key if the entire application is deployed as a Windows Azure hosted service. CMSAllowCacheByCulture (true) - If true, the system adds culture code to the cache keys where needed, if false, it shares the cache for all cultures. CMSPartialCacheItems ("username;sitename;lang") - Defines the parts of the cache key used for partial cache of the controls. List of items separated by semicolon. Available options: viewmode, username, sitename, lang, browser, domain, gzip CMSOutputCacheItems (“username;sitename;lang;browser;cookielevel;deviceprofile”) - Defines the parts of the cache key used for output caching. List of items separated by semicolon. Available options: viewmode, username, sitename, lang, browser, domain, gzip CMSAllowCacheByUserName (true)- If true, the system adds user name to the cache keys where needed, if false, it shares the cache for all users. CMSClearOutputCacheOnPostback (true) – if output cache is cleared on post back CMSCacheURLRewriting (0)- Cache url rewriting in minutes

Additional resources Cache dependencies explained: devnet.kentico.com/Blogs/Martin-Hejtmanek/August-2010/Deep-dive--Cache-dependencies.aspx New caching mechanism (version 5.5+): devnet.kentico.com/Blogs/Martin-Hejtmanek/June-2010/New-in-5-5--Caching-API.aspx Old webinar about caching: devnet.kentico.com/Blogs/Martin-Hejtmanek/October-2009/Webinar-2---Performance-optimization-and-caching-i.aspx (old API) Documentation: devnet.kentico.com/docs/devguide/caching_options.htm Deep dive caching blog post: devnet.kentico.com/Blogs/Martin-Hejtmanek/April-2009/Deep-Dive---Kentico-CMS-Caching.aspx Blog post about optimization of your code: devnet.kentico.com/Blogs/Martin-Hejtmanek/January-2010/Optimization-tip--Write-better-code,-disable-Outpu.aspx Cache item name usage: devnet.kentico.com/Blogs/Martin-Hejtmanek/December-2009/Tip--Is-your-menu-and-controls-cache-settings-effi.aspx API caching examples: http://devnet.kentico.com/Knowledge-Base/API-and-Internals/Caching-API-examples.aspx

Questions & Answers ?

Thank you!