{"id":1896565,"date":"2019-10-18T13:19:29","date_gmt":"2019-10-18T17:19:29","guid":{"rendered":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/caching-month-view-html-in-transients\/"},"modified":"2025-03-05T11:28:53","modified_gmt":"2025-03-05T16:28:53","slug":"caching-month-view-html-in-transients","status":"publish","type":"post","link":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/caching-month-view-html-in-transients\/","title":{"rendered":"Enabling Caching in Views"},"content":{"rendered":"\n<p>We have a setting in The Events Calendar that helps speed up the calendar month view by caching the events on the calendar, so they load faster on the next page refresh.<\/p>\n\n\n\n<p>You&#8217;ll find the &#8220;Enable the Month View Cache setting at\u00a0<strong>Events \u2192 Settings \u2192 General<\/strong><em> <strong>\u2192<\/strong><\/em> <strong>Viewing<\/strong><em>.\u00a0<\/em>Selecting that option will save the HTML for your Month View in a <a href=\"https:\/\/codex.wordpress.org\/Transients_API\" target=\"_blank\" rel=\"noopener noreferrer\">transient<\/a>. That way, the events don&#8217;t have to be pulled from the database of everything the site is visited. Instead, the calendar displays the saved HTML fragment and loads faster as a result.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"713\" height=\"739\" src=\"https:\/\/images.theeventscalendar.com\/kb\/uploads\/2019\/10\/month-view-cache.png\" alt=\"\" class=\"wp-image-1964488\" style=\"width:1096px;height:auto\" srcset=\"https:\/\/images.theeventscalendar.com\/kb\/uploads\/2019\/10\/month-view-cache.png 713w, https:\/\/images.theeventscalendar.com\/kb\/uploads\/2019\/10\/month-view-cache-289x300.png 289w\" sizes=\"auto, (max-width: 713px) 100vw, 713px\" \/><\/figure>\n\n\n\n<p>If you are customizing the month view template, you&#8217;ll probably want to disable this setting because there&#8217;s a chance that the plugin&#8217;s template file will load instead of your custom version. By disabling this setting, your changes to the template will always load. That said, you can keep the setting enabled and toggle it to refresh the cache and display your changes. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-calendar-views\">Calendar views<\/h2>\n\n\n\n<p>We <a href=\"https:\/\/theeventscalendar.com\/the-events-calendar-5-0-0\/\" target=\"_blank\" rel=\"noreferrer noopener\">released updates to the calendar view designs<\/a> in The Events Calendar 5.0. This introduced a lot more flexibility to how HTML caching behaves, including a way to filter when something is cached as well as fully deactivate cache from loading altogether.<\/p>\n\n\n\n<p>The  <code>tribe_events_views_v2_should_cache_html<\/code> filter accepts three parameters, one of which allows more control over when to cache.<\/p>\n\n\n\n<p>For example, disabling cache can be done with a filter in your <code>functions.php<\/code> file:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\n&lt;?php\nadd_filter( &#039;tribe_events_views_v2_should_cache_html&#039;, &#039;__return_false&#039; );\n<\/pre><\/div>\n\n\n<p class=\"has-text-color has-background\" style=\"color:#141827;background-color:var(--global-palette8)\">This snippet is capable of lots of other things. But please note that caching is not something to be modified unless you are very aware of possible security consequences.<\/p>\n\n\n\n<p>Normal expiration is a full day in seconds, but you can modify that using a filter as well:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\n&lt;?php\nadd_filter( &#039;tribe_events_views_v2_cache_html_expiration&#039;, function() {\n    return 2 * DAY_IN_SECONDS;\n} );\n<\/pre><\/div>\n\n\n<p>It&#8217;s worth noting that the calendar&#8217;s week and month only cache two months&#8217; worth of past events and up to one year of upcoming events.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>We have a setting in The Events Calendar that helps speed up the calendar month view by caching the events on the calendar, so they load faster on the next page refresh. You&#8217;ll find the &#8220;Enable the Month View Cache setting at\u00a0Events \u2192 Settings \u2192 General \u2192 Viewing.\u00a0Selecting that option will save the HTML for&#8230;<\/p>\n","protected":false},"author":3,"featured_media":1955565,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_kad_blocks_custom_css":"","_kad_blocks_head_custom_js":"","_kad_blocks_body_custom_js":"","_kad_blocks_footer_custom_js":"","_swpsp_post_exclude":false,"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"ep_exclude_from_search":false,"footnotes":""},"categories":[130],"tags":[12],"stellar-product-taxonomy":[161],"class_list":["post-1896565","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-advanced-post-manager","tag-5-x-calendar-views","stellar-product-taxonomy-the-events-calendar"],"acf":[],"taxonomy_info":{"category":[{"value":130,"label":"Managing Events"}],"post_tag":[{"value":12,"label":"5.x calendar views"}],"stellar-product-taxonomy":[{"value":161,"label":"The Events Calendar"}]},"featured_image_src_large":["https:\/\/images.theeventscalendar.com\/kb\/uploads\/2023\/02\/social-share-1024x538.png",1024,538,true],"author_info":{"display_name":"Jaime Marchwinski","author_link":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/author\/jaimetri-be\/"},"comment_info":0,"category_info":[{"term_id":130,"name":"Managing Events","slug":"advanced-post-manager","term_group":0,"term_taxonomy_id":130,"taxonomy":"category","description":"","parent":61,"count":44,"filter":"raw","term_order":"0","cat_ID":130,"category_count":44,"category_description":"","cat_name":"Managing Events","category_nicename":"advanced-post-manager","category_parent":61}],"tag_info":[{"term_id":12,"name":"5.x calendar views","slug":"5-x-calendar-views","term_group":0,"term_taxonomy_id":12,"taxonomy":"post_tag","description":"","parent":0,"count":7,"filter":"raw","term_order":"0"}],"_links":{"self":[{"href":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/posts\/1896565","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/comments?post=1896565"}],"version-history":[{"count":2,"href":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/posts\/1896565\/revisions"}],"predecessor-version":[{"id":1964489,"href":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/posts\/1896565\/revisions\/1964489"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/media\/1955565"}],"wp:attachment":[{"href":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/media?parent=1896565"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/categories?post=1896565"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/tags?post=1896565"},{"taxonomy":"stellar-product-taxonomy","embeddable":true,"href":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/stellar-product-taxonomy?post=1896565"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}