Download presentation
Presentation is loading. Please wait.
Published byLucy Ross Modified over 8 years ago
1
Performance optimization and caching in Kentico CMS Martin Hejtmanek (CTO), martinh@kentico.commartinh@kentico.com Webinar 9/16/2009
2
Topics Caching options in Kentico CMS Using caching in your code The difference between good and bad code SQL debug options Cache debug options ViewState debug options Designing the right structure of the web site Most common mistakes and how to avoid them
3
Caching options in Kentico CMS Page info caching – Basic document information Content caching – Content data for the controls Partial caching – since 4.1 Full page (output) caching Image (file) caching – GetFile etc. API – CacheHelper http://devnet.kentico.com/Blogs/Martin-Hejtmanek/April-2009 /Deep-Dive---Kentico-CMS-Caching.aspx Motto: Cache everything you can or wait for your pages to load!
4
Using caching in your code Standard way (multiline) object result = null; string useCacheItemName = "myCacheKey"; if (!CacheHelper.TryGetItem(useCacheItemName, out result)) { // Get the data result = TreeHelper.SelectNodes("/%", false, "CMS.News"); // Save the result to the cache CacheHelper.Add(useCacheItemName, result, null, DateTime.Now.AddMinutes(10), System.Web.Caching.Cache.NoSlidingExpiration); } Complex way (singleline) DataSet resultComplex = DataCacheHelper.GetCached3 ("/%", false, "CMS.News", TreeHelper.SelectNodes, "myKeyComplex", 10, false, null, null);
5
Good vs. bad code (1) Bad code TreeProvider tree = new TreeProvider(); DataSet ds = tree.SelectNodes(CMSContext.CurrentSite.SiteName, "/News/%", CMSContext.PreferredCultureCode, false, null, null, null, -1, true); foreach (DataRow dr in ds.Tables[0].Rows) { tree = new TreeProvider(); int nodeId = ValidationHelper.GetInteger(dr["NodeID"], 0); TreeNode node = tree.SelectSingleNode(nodeId); ltlResponse.Text += node.GetValue("NewsTitle") + " "; } Using complete context object to get simple value (SiteName) Creating new TreeProvider for every item Calling subqueries in the loop (SelectSingleNode) Creating unnecessary objects to get values (SelectSingleNode)
6
Good vs. bad code (2) Better code TreeProvider tree = new TreeProvider(); string siteName = CMSContext.CurrentSiteName; DataSet ds = tree.SelectNodes(siteName, "/News/%", CMSContext.PreferredCultureCode, false, null, null, null, -1, true); foreach (DataRow dr in ds.Tables[0].Rows) { string aliasPath = ValidationHelper.GetString(dr["NodeAliasPath"], ""); string className = ValidationHelper.GetString(dr["ClassName"], ""); TreeNode node = tree.SelectSingleNode(siteName, aliasPath, CMSContext.PreferredCultureCode, false, className); ltlResponse.Text += node.GetValue("NewsTitle") + " "; } Calling subqueries in the loop (SelectSingleNode) – less Creating unnecessary objects to get values (SelectSingleNode)
7
Good vs. bad code (3) Best code TreeProvider tree = new TreeProvider(); DataSet ds = tree.SelectNodes(CMSContext.CurrentSiteName, "/News/%", CMSContext.PreferredCultureCode, false, "CMS.News", null, null, -1, true); foreach (DataRow dr in ds.Tables[0].Rows) { ltlResponse.Text += dr["NewsTitle"] + " "; } Only single query, no other queries needed for the items Motto: There is always a way how to make things better.
8
SQL debug options web.config: Site manager -> Administration -> System -> SQL debug
9
Cache debug options web.config Site manager -> Administration -> System -> Cache debug
10
ViewState debug options web.config Site manager -> Administration -> System -> ViewState debug
11
The right structure of the web site (1) Which news was released first on 9/16/2002 ? How many news were released in August ? Which of the sites structures feels better? Site (CMS.Root) News (Page.MenuItem) News 1 (CMS.News) News 2 News 3 News 4 News 5 News 6 … News 1000 … News 12345 Site 2 (CMS.Root) News (Page.MenuItem) 2002 (Custom.NewsYear) August (Custom.NewsMonth) News 1 (CMS.News) … News 4 September News 5 … News 123 2009 September News 12345
12
The right structure of the web site (2) Questions before you start designing the web site: What is the purpose of the web site? How will it’s life cycle look like? How many documents and in what time frame will be there? What information will you need to display and report? What your boss (client) may want to implement in the future? 80/20 - 80% of the development are the 20% of the features (the ones that weren’t addressed by the original requirements) – minimize that Phase 2 – How to ask for the pay rise for being more productive than others How does the typical visitor behave? (which pages must be fastest) Is the URL friendly enough (can you see the logical structure in it)? Does the designed content structure allow this behavior? Which best type of cache can be used for particular sections?
13
Most common mistakes Not taking care about performance at all (nothing is automatic) Relying on the basic API to cache things (not everything can be cached natively) Creating the same objects over and over (TreeProvider, Connection) Using way too many loops (most things can be done in a single pass) Being too lazy to work with “low-level” objects such as DataRow (new and nicer objects mean more overhead) Being too lazy to use methods with more parameters or overlook them (the more the method gets, the less needs to get from DB) Overlooking that you already have the the required information available (querying API for things that are already in your original DataSet) Not doing load tests before the site is live (it is like checking if the wine is poisoned by drinking it and see what happens)
14
Q&A Now is the time for your questions The webinar recording will be available on our new Partner portal and later on the DevNet.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.