Successfully reported this slideshow.
Your SlideShare is downloading. ×

Caching in Kentico 11

Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Loading in …3
×

Check these out next

1 of 15 Ad

Caching in Kentico 11

Download to read offline

Kentico offers a variety of levels at which you can cache content - This presentation goes over the methods of caching, how to implement them, and links to Kentico documentation for each process. This presentation has been confirmed to apply to Kentico versions 9-11

Kentico offers a variety of levels at which you can cache content - This presentation goes over the methods of caching, how to implement them, and links to Kentico documentation for each process. This presentation has been confirmed to apply to Kentico versions 9-11

Advertisement
Advertisement

More Related Content

Similar to Caching in Kentico 11 (20)

Advertisement

Recently uploaded (20)

Caching in Kentico 11

  1. 1. CACHING IN KENTICO Chris Bass, Wakefly Kentico Evangelist
  2. 2. HOW MANY TYPES OF CACHING ARE IN KENTICO 11? • Output Caching (Full Page HTML Caching) • Partial Caching (Web Part HTML Caching) • Content Caching (Data Source Caching) • File Caching (Attachments, Media Items, etc.) • Page Info Caching (PageInfoProvider) • Progressive Caching (Concurrent User Result Caching)
  3. 3. CACHE PRINCIPLES • https://docs.kentico.com/display/K11/Configuring+cachi ng • Caching in Kentico consists primarily of trading W3WP process memory for end-user performance. The more you store in the process memory, the faster data will be served to end-users, but the more RAM Kentico needs to keep up. • Kentico handles caching internally through a one-way linked list of key-values. When one is cleared, anything down the one-way path from it will be cleared as well. • Kentico recommends using all levels of caching, setting progressively higher timeouts as you get more granular, so even when the full-page cache is expired, individual content with higher tolerances for caching can still be cached.
  4. 4. CACHE DEPENDENCIES • Kentico allows creation of “Dummy Keys” – cache entries which don’t have useful data, but are in the key-value list, such that editing them clears all the cache down the line from them. • A full list is here: • https://docs.kentico.com/display/K11/Setti ng+cache+dependencies • For all of Kentico’s internal dependencies, Kentico clears them when a change is made through the UI or API. • To clear your own, call CacheHelper.TouchKey(“mycustomdata| mycustomkey”); • Example keys: • node|sitename|/home • node|sitename|/home|en-us • node|sitename|/|childnodes • nodes|sitename|cms.menuitem|all • documentid|56|attachments • cms.user|byid|53 • template|12 • cms.form|all • mycustomdata|mycustomkey • You’d have to touch this one yourself to clear things that depend on it
  5. 5. OUTPUT CACHING • https://docs.kentico.com/display/K11/Caching+page+output • Caches the full, processed HTML output that is sent to the client for a page. • To Enable: System -> Performance --> Output Caching • “Enable output caching” • Then you also need to enable it per-page in Properties -> Generic (or at a parent page to inherit) • Recommendation: Don’t set “Allow file system cache”. When the app restarts, the file system cache is decoupled from the in-memory cache and will continue serving outdated content, and you’ll have to manually go to System->Clear Cache in order to fix it.
  6. 6. FLUSHING THE OUTPUT CACHE • If you edit the Page (Page tab, Form tab, Properties tab) or the Template. • If a user viewing the page performs a Postback (submitting a form, for example) • Unsure about Ajax postbacks, but I’d suspect so. • This makes Output cache mostly useless for pages with Forms or dynamic controls • If any of the global output cache variables (In Settings) are touched, ALL relevant pages’ caches are flushed. • By placing an “Output cache dependencies” web part on a page, you can set manual cache dependencies per page. • Manually in the CMS Desk (System -> Clear Cache) or restarting IIS
  7. 7. OUTPUT CACHING: CACHE VARIABLES • https://docs.kentico.com/display/K11/Caching+page+output#Cachingpageoutput-Cachingmultipleoutputversionsofpages • Cache Variables let you globally dictate keys on which Kentico will split a page’s output cache. • You can enable or disable separate output caches for: • username - every logged in user (public users share the same output cache). • sitename - every site in the system (leave checked unless your sites all have identical content on pages with the same path). • lang - each language version of pages. • browser - different types of web browsers detected by Kentico. • cookielevel - the cookie level preferences of visitors. • deviceprofile - the device profiles detected for visitors. • domain - the website domain name (check to disable output cache sharing between different domain aliases of sites). • viewmode - the page view modes used by Kentico, such as design, edit, preview or live site. Currently, the system only uses caching for the live site view mode, so I believe this cache variable is unused. • The output cache always creates separate cache items based on the: • Page path (including the virtual directory and extension) • Protocol in the request URL
  8. 8. OUTPUT CACHING: SUBSTITUTION MACROS • https://docs.kentico.com/display/K11/Using+output+cache+substitutions • Even when cached, you can set specific custom Macro methods to be executable every page load. • To do so, create a Module file in App_Code, and create a single macro- parsing method that attaches to the ResponseOutputFilter.OnResolveSubstitution event (using OnInit). • The method to the right would handle the {~ TimeStamp ~} substitution macro. • Using this substitution macro would resolve with the current time, even if the page was otherwise cached. If you just did a standard macro, like {% DateTime.Now %}, it would display the timestamp as of when the page was first cached. private void ResolveCustomOutputSubstitutions(object sender, SubstitutionEventArgs e) { // Checks that the substitution expression is not resolved yet if (!e.Match) { // Branches according to the expression text of the substitution macro // You can define any number of substitution macros by adding further cases switch (e.Expression.ToLower()) { // Handles the {~TimeStamp~} substitution macro case "timestamp": // Flags the substitution expression as resolved e.Match = true; // Returns the current time as the result of the substitution e.Result = DateTime.Now.ToString(); break; } }
  9. 9. PARTIAL CACHING • When you want to cache parts of a page, but not all of it, as full HTML output, you can cache individual web parts. • Other good uses are for master page content, or want to use different cache intervals or dependencies that are different than the full-page cache. • Similar to full-page caching, you need to enable it in Settings -> Performance and then configure it on the web part instance (Performance category). • Cache is cleared: • When the properties of the web part are configured. • On Postback on a page with the web part • Editable web parts clear their cache when the content of their page is updated. • When you configure Partial Cache Dependencies (Performance category), those will also clear it. • Manually, in System -> Clear Cache or IIS restart • Not suitable for lists with filters or other web parts whose output-content changes often.
  10. 10. CONTENT CACHING • https://docs.kentico.com/display/K11/Caching+the+data+of+page+components • Even if the display of a page cannot be cached for one reason or another, the data source (SQL, the CMS tree, etc) often can. • Any web part in Kentico with its own data source, such as repeaters, Data Source controls, and navigation web parts, will have Content caching properties exposed. You can also expose content caching on custom web parts, but you will need to code the cache key and caching logic yourself. • Because Kentico uses dummy cache keys, any pages using the same template (and so, same web part) will share content, so even the first load of a page might be partially cached already. • Similar to Output caching, you must configure it globally and locally: System -> Performance -> “Cache Content”, and per-template, on the web part. • The default cache key is unique per web part, but you can give a Cache Item Name on the web part to share data between different web parts. Keep in mind if you do this, you should make any important variables part of the cache name, so if the page has different content, it’ll not try to use the same key.
  11. 11. FILE CACHING • https://docs.kentico.com/display/K11/Caching+files+and+resources • This refers to things such as the CSS Stylesheets, Javascript, and attachments served by Kentico. • Two types – client-side, server-side. • Client: System -> Performance, Client cache. This setting applies to dynamic files, such as the CSS stylesheets. • Physical files served through GetResource use a web.config key that defaults to one week, CMSPhysicalFilesCacheMinutes. • Files served directly instead of through Kentico, just use IIS. • Enabling “Allow client cache revalidation” makes browsers re-validate the cache each time by requesting the last-updated time as a header – it’ll ensure users are less likely to see out-of-date content, but forces an extra (small) request each time. • Server: • For files in the database, the cache holds the entire file as well as metadata. • This is why we don’t store large files in the database (also it’s inefficient) • For files in the File system (or in both places), only the metadata is cached, the file itself uses the IIS settings. • System -> Performance -> Cache Files (minutes) • The system always caches files for at least one minute, as DoS protection. • If you’re using Azure/Amazon S3 for separated file storage, you need to manually clear the file caches. (uncommon, but be aware)
  12. 12. PAGE INFO CACHING • https://docs.kentico.com/display/K11/Configuring+caching#Configuringcaching-Pageinfocaching • Basic info about documents is always cached on viewing a page: • alias path • ID and name • document metadata and other properties • SKU information (for products) • workflow information • This cache is managed automatically, cleared when the appropriate info is edited, and can be accessed by using PageInfoProvider, instead of DocumentInfoProvider. • The length is configurable: System -> Performance -> Cache Page info (minutes). • Kentico mysteriously warns: “Do NOT set the value lower than 10 minutes”. • Presumably because gremlins? • Just use it always when possible.
  13. 13. PROGRESSIVE CACHING • To Enable/Disable: System -> Performance • “Use progressive caching” • If checked, Kentico will connect the threads of uncached data access so that multiple users concurrently accessing one dataset will share a single thread rather than calling the same data multiple times. • This supposedly leads to better performance if the website is under extremely heavy loads, but probably slows down an individual user’s access to the data. • There’s no documentation on how long a thread waits for other “similar” threads to compound before executing the request. • It’s unlikely to have much effect if you’re doing other caching, but for an existing site that is uncached but having heavy load, this may help until more thorough caching can be done.
  14. 14. FINAL NOTES • There’s also the ability to cache individual macros: • https://docs.kentico.com/display/K11/Caching+the+results+of+macros • And here is documentation on how to implement caching in your custom code: • https://docs.kentico.com/display/K11/Caching+in+custom+code • Here are some example scenarios from Kentico and best practices: • https://docs.kentico.com/display/K11/Caching+best+practices+for+typical+projects • Here is how you can debug Kentico’s cache in the CMS Desk: • https://docs.kentico.com/display/K11/Debugging+cache • Don’t forget to do minification/compression for your CSS/JS: • https://docs.kentico.com/display/K11/Using+code+minification+and+compression • And finally, some more generic notes on optimizing your performance: • https://docs.kentico.com/display/K11/Optimizing+website+performance
  15. 15. THANKS FOR STAYING AWAKE

×