<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>caching framework &#8211; Aimeos</title>
	<atom:link href="https://aimeos.org/tips/tag/caching-framework/feed/" rel="self" type="application/rss+xml" />
	<link>https://aimeos.org/tips</link>
	<description>ultra fast PHP e-commerce framework</description>
	<lastBuildDate>Mon, 29 Jul 2019 17:19:12 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=5.7.8</generator>

<image>
	<url>https://aimeos.org/tips/wp-content/uploads/2019/09/Aimeos_e_200-100x104.png</url>
	<title>caching framework &#8211; Aimeos</title>
	<link>https://aimeos.org/tips</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>How to use the TYPO3 caching framework with cache groups</title>
		<link>https://aimeos.org/tips/how-to-use-the-typo3-caching-framework-with-cache-groups/</link>
					<comments>https://aimeos.org/tips/how-to-use-the-typo3-caching-framework-with-cache-groups/#respond</comments>
		
		<dc:creator><![CDATA[aimeos]]></dc:creator>
		<pubDate>Tue, 25 Aug 2015 10:52:53 +0000</pubDate>
				<category><![CDATA[TYPO3]]></category>
		<category><![CDATA[cache group]]></category>
		<category><![CDATA[caching framework]]></category>
		<guid isPermaLink="false">https://aimeos.org/tips/?p=139</guid>

					<description><![CDATA[The TYPO3 caching framework is a great way to speed up your site if your extension needs to perform tasks that can be cached. In the Aimeos TYPO3 extension, we use it to store content like list or detail views<span class="ellipsis">&#8230;</span><div class="read-more"><a href="https://aimeos.org/tips/how-to-use-the-typo3-caching-framework-with-cache-groups/">Read more <span class="screen-reader-text">How to use the TYPO3 caching framework with cache groups</span><span class="meta-nav"> &#8250;</span></a></div><!-- end of .read-more -->]]></description>
										<content:encoded><![CDATA[<p>The TYPO3 caching framework is a great way to speed up your site if your extension needs to perform tasks that can be cached. In the <a href="http://typo3.org/extensions/repository/view/aimeos">Aimeos TYPO3 extension</a>, we use it to store content like list or detail views of the web shop to get lightning fast response times. Since version 6.2, a cache can belong to one or more cache groups in the caching framework and it enables editors to control more precisely which caches should be flushed. Unfortunately, this features isn&#8217;t well documented yet in the TYPO3 documentation but here&#8217;s the remedy!</p>
<p><span id="more-139"></span></p>
<h2>What are cache groups</h2>
<p>In the TYPO3 caching framework, there are currently three types of caches:</p>
<ul>
<li><strong>pages</strong> : Front-end related caches</li>
<li><strong>system</strong> : Low-level caches that shouldn&#8217;t normally be flushed</li>
<li><strong>all</strong> : All other caches that don&#8217;t fall into one of the two categories before</li>
</ul>
<p>Based on the cache type (a.k.a cache group) the caches are flushed on different occasions. This makes a difference for the editors because depending on what they have changed, most often one of the cache groups will be flushed as well. Also, there are at least two options available when editors decide to flush the caches manually:</p>
<p><a href="https://aimeos.org/tips/wp-content/uploads/2015/08/Aimeos-typo3-cache7.png"><img class="aligncenter wp-image-142" src="https://aimeos.org/tips/wp-content/uploads/2015/08/Aimeos-typo3-cache7.png" alt="Aimeos-typo3-cache7" width="300" height="150" srcset="https://aimeos.org/tips/wp-content/uploads/2015/08/Aimeos-typo3-cache7.png 300w, https://aimeos.org/tips/wp-content/uploads/2015/08/Aimeos-typo3-cache7-100x50.png 100w, https://aimeos.org/tips/wp-content/uploads/2015/08/Aimeos-typo3-cache7-150x75.png 150w, https://aimeos.org/tips/wp-content/uploads/2015/08/Aimeos-typo3-cache7-200x100.png 200w" sizes="(max-width: 300px) 100vw, 300px" /></a>The first option will only flush front-end related caches while the second one flushes all caches that are not in the &#8220;system&#8221; or &#8220;pages&#8221; cache group. Flushing the &#8220;system&#8221; caches isn&#8217;t that easy any more but those don&#8217;t need to be cleared at all by editors. Instead, they are automatically flushed if e.g. a new extension is installed.</p>
<p>Therefore, it makes sense to tell TYPO3 which cache group your cache should be in if you use the caching framework to store data temporarily. This allows at least editors to selectively flush caches instead of the famous &#8220;flush all caches to be sure&#8221;! More information about which cache in in which cache group can be found in the article about the <a href="https://docs.typo3.org/typo3cms/CoreApiReference/CachingFramework/Architecture/Index.html#caching-architecture-core">TYPO3 caching architecture</a>.</p>
<h2>Set up your extension cache</h2>
<p>To create your own cache in your TYPO3 extension, there are only a few lines in the <code>ext_localconf.php</code> of your extension necessary. You can copy and paste these lines and only have to replace the <code>aimeos</code> string by the name of your own TYPO3 extension:</p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="php"><pre class="de1"><span class="kw1">if</span><span class="br0">&#40;</span> <span class="sy0">!</span><span class="kw3">is_array</span><span class="br0">&#40;</span> <span class="re0">$TYPO3_CONF_VARS</span><span class="br0">&#91;</span><span class="st_h">'SYS'</span><span class="br0">&#93;</span><span class="br0">&#91;</span><span class="st_h">'caching'</span><span class="br0">&#93;</span><span class="br0">&#91;</span><span class="st_h">'cacheConfigurations'</span><span class="br0">&#93;</span><span class="br0">&#91;</span><span class="st_h">'aimeos'</span><span class="br0">&#93;</span> <span class="br0">&#41;</span> <span class="br0">&#41;</span> <span class="br0">&#123;</span>
    <span class="re0">$TYPO3_CONF_VARS</span><span class="br0">&#91;</span><span class="st_h">'SYS'</span><span class="br0">&#93;</span><span class="br0">&#91;</span><span class="st_h">'caching'</span><span class="br0">&#93;</span><span class="br0">&#91;</span><span class="st_h">'cacheConfigurations'</span><span class="br0">&#93;</span><span class="br0">&#91;</span><span class="st_h">'aimeos'</span><span class="br0">&#93;</span> <span class="sy0">=</span> <span class="kw3">array</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
&nbsp;
<span class="kw1">if</span><span class="br0">&#40;</span> <span class="sy0">!</span><span class="kw3">isset</span><span class="br0">&#40;</span><span class="re0">$TYPO3_CONF_VARS</span><span class="br0">&#91;</span><span class="st_h">'SYS'</span><span class="br0">&#93;</span><span class="br0">&#91;</span><span class="st_h">'caching'</span><span class="br0">&#93;</span><span class="br0">&#91;</span><span class="st_h">'cacheConfigurations'</span><span class="br0">&#93;</span><span class="br0">&#91;</span><span class="st_h">'aimeos'</span><span class="br0">&#93;</span><span class="br0">&#91;</span><span class="st_h">'frontend'</span><span class="br0">&#93;</span> <span class="br0">&#41;</span> <span class="br0">&#41;</span> <span class="br0">&#123;</span>
    <span class="re0">$TYPO3_CONF_VARS</span><span class="br0">&#91;</span><span class="st_h">'SYS'</span><span class="br0">&#93;</span><span class="br0">&#91;</span><span class="st_h">'caching'</span><span class="br0">&#93;</span><span class="br0">&#91;</span><span class="st_h">'cacheConfigurations'</span><span class="br0">&#93;</span><span class="br0">&#91;</span><span class="st_h">'aimeos'</span><span class="br0">&#93;</span><span class="br0">&#91;</span><span class="st_h">'frontend'</span><span class="br0">&#93;</span> <span class="sy0">=</span> <span class="st_h">'TYPO3\\CMS\\Core\\Cache\\Frontend\\StringFrontend'</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
&nbsp;
<span class="kw1">if</span><span class="br0">&#40;</span> <span class="sy0">!</span><span class="kw3">isset</span><span class="br0">&#40;</span><span class="re0">$TYPO3_CONF_VARS</span><span class="br0">&#91;</span><span class="st_h">'SYS'</span><span class="br0">&#93;</span><span class="br0">&#91;</span><span class="st_h">'caching'</span><span class="br0">&#93;</span><span class="br0">&#91;</span><span class="st_h">'cacheConfigurations'</span><span class="br0">&#93;</span><span class="br0">&#91;</span><span class="st_h">'aimeos'</span><span class="br0">&#93;</span><span class="br0">&#91;</span><span class="st_h">'backend'</span><span class="br0">&#93;</span> <span class="br0">&#41;</span> <span class="br0">&#41;</span> <span class="br0">&#123;</span>
    <span class="re0">$TYPO3_CONF_VARS</span><span class="br0">&#91;</span><span class="st_h">'SYS'</span><span class="br0">&#93;</span><span class="br0">&#91;</span><span class="st_h">'caching'</span><span class="br0">&#93;</span><span class="br0">&#91;</span><span class="st_h">'cacheConfigurations'</span><span class="br0">&#93;</span><span class="br0">&#91;</span><span class="st_h">'aimeos'</span><span class="br0">&#93;</span><span class="br0">&#91;</span><span class="st_h">'backend'</span><span class="br0">&#93;</span> <span class="sy0">=</span> <span class="st_h">'TYPO3\\CMS\\Core\\Cache\\Backend\\DatabaseBackend'</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
&nbsp;
<span class="kw1">if</span><span class="br0">&#40;</span> <span class="sy0">!</span><span class="kw3">isset</span><span class="br0">&#40;</span><span class="re0">$TYPO3_CONF_VARS</span><span class="br0">&#91;</span><span class="st_h">'SYS'</span><span class="br0">&#93;</span><span class="br0">&#91;</span><span class="st_h">'caching'</span><span class="br0">&#93;</span><span class="br0">&#91;</span><span class="st_h">'cacheConfigurations'</span><span class="br0">&#93;</span><span class="br0">&#91;</span><span class="st_h">'aimeos'</span><span class="br0">&#93;</span><span class="br0">&#91;</span><span class="st_h">'options'</span><span class="br0">&#93;</span> <span class="br0">&#41;</span> <span class="br0">&#41;</span> <span class="br0">&#123;</span>
	<span class="re0">$TYPO3_CONF_VARS</span><span class="br0">&#91;</span><span class="st_h">'SYS'</span><span class="br0">&#93;</span><span class="br0">&#91;</span><span class="st_h">'caching'</span><span class="br0">&#93;</span><span class="br0">&#91;</span><span class="st_h">'cacheConfigurations'</span><span class="br0">&#93;</span><span class="br0">&#91;</span><span class="st_h">'aimeos'</span><span class="br0">&#93;</span><span class="br0">&#91;</span><span class="st_h">'options'</span><span class="br0">&#93;</span> <span class="sy0">=</span> <span class="kw3">array</span><span class="br0">&#40;</span> <span class="st_h">'defaultLifetime'</span> <span class="sy0">=&amp;</span>gt<span class="sy0">;</span> <span class="nu0">0</span> <span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
&nbsp;
<span class="kw1">if</span><span class="br0">&#40;</span> <span class="sy0">!</span><span class="kw3">isset</span><span class="br0">&#40;</span><span class="re0">$TYPO3_CONF_VARS</span><span class="br0">&#91;</span><span class="st_h">'SYS'</span><span class="br0">&#93;</span><span class="br0">&#91;</span><span class="st_h">'caching'</span><span class="br0">&#93;</span><span class="br0">&#91;</span><span class="st_h">'cacheConfigurations'</span><span class="br0">&#93;</span><span class="br0">&#91;</span><span class="st_h">'aimeos'</span><span class="br0">&#93;</span><span class="br0">&#91;</span><span class="st_h">'groups'</span><span class="br0">&#93;</span> <span class="br0">&#41;</span> <span class="br0">&#41;</span> <span class="br0">&#123;</span>
	<span class="re0">$TYPO3_CONF_VARS</span><span class="br0">&#91;</span><span class="st_h">'SYS'</span><span class="br0">&#93;</span><span class="br0">&#91;</span><span class="st_h">'caching'</span><span class="br0">&#93;</span><span class="br0">&#91;</span><span class="st_h">'cacheConfigurations'</span><span class="br0">&#93;</span><span class="br0">&#91;</span><span class="st_h">'aimeos'</span><span class="br0">&#93;</span><span class="br0">&#91;</span><span class="st_h">'groups'</span><span class="br0">&#93;</span> <span class="sy0">=</span> <span class="kw3">array</span><span class="br0">&#40;</span> <span class="st_h">'pages'</span> <span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span></pre></div></div></div></div></div></div></div>


<p>The whole if/is_array/isset thing is necessary to allow administrators to overwrite your settings in the <code>typo3conf/LocalConfiguration.php</code> file as the configuration of your extension is loaded afterwards. Thus, it would overwrite any previous configuration settings if you don&#8217;t check first if they exist.</p>
<p>There are four settings you can use to configure your cache in the TYPO3 caching framework:</p>
<ul>
<li><strong>frontend</strong> : What type of data is accepted</li>
<li><strong>backend</strong> : Where is the data stored</li>
<li><strong>options</strong> : Additional configuration settings for the back-end</li>
<li><strong>groups</strong> : The cache groups your extension cache belongs to</li>
</ul>
<p>There&#8217;s the choice between two cache front-ends and several cache back-ends. A complete list of both including their options is available in the <a href="https://docs.typo3.org/typo3cms/CoreApiReference/CachingFramework/FrontendsBackends/Index.html">TYPO3 cache front-end/back-end</a> article. The <code>groups</code> setting can be either <code>pages</code>, <code>system</code>, <code>all</code> or a combination thereof. Normally, you should use only one cache group and the group <code>all</code> is the default value if you don&#8217;t specify one.</p>
<div class="caution">If you use the default <code>database</code> back-end, you should be aware that the default lifetime of cached entries is only <strong>ONE HOUR</strong> if you don&#8217;t set it to a different value or to unlimited (&#8220;0&#8221;) like in the example above. Don&#8217;t forget to set up the <strong>&#8220;Caching framework garbage collection&#8221;</strong> scheduler task to clean up old entries. Otherwise, your cache tables will grow infinitely!</div>
<h2>Use your new cache</h2>
<p>Once set up, you can access the cache everywhere in you TYPO3 extension and you only have to write a few lines:</p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="php"><pre class="de1"><span class="re0">$name</span> <span class="sy0">=</span> <span class="st_h">'TYPO3\\CMS\\Core\\Cache\\CacheManager'</span><span class="sy0">;</span>
<span class="re0">$manager</span> <span class="sy0">=</span> \TYPO3\CMS\Core\Utility\GeneralUtility<span class="sy0">::</span><span class="me2">makeInstance</span><span class="br0">&#40;</span> <span class="re0">$name</span> <span class="br0">&#41;</span><span class="sy0">;</span>
<span class="re0">$cache</span> <span class="sy0">=</span> <span class="re0">$manager</span><span class="sy0">-&amp;</span>gt<span class="sy0">;</span>getCache<span class="br0">&#40;</span> <span class="st_h">'aimeos'</span> <span class="br0">&#41;</span><span class="sy0">;</span></pre></div></div></div></div></div></div></div>


<p>They create an instance of the cache manager and retrieve your cache by name. Replace <code>aimeos</code> with the name of your extension resp. the name you&#8217;ve used in your <code>ext_localconf.php</code> in the cache setup code. Now you are able to set and get cached entries or remove them from the cache again:</p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="php"><pre class="de1"><span class="re0">$cache</span><span class="sy0">-&amp;</span>gt<span class="sy0">;</span>set<span class="br0">&#40;</span> <span class="st_h">'auniqueidentifier'</span><span class="sy0">,</span> <span class="re0">$data</span><span class="sy0">,</span> <span class="kw3">array</span><span class="br0">&#40;</span> <span class="st_h">'tag1'</span><span class="sy0">,</span> <span class="st_h">'tag2'</span> <span class="br0">&#41;</span> <span class="br0">&#41;</span><span class="sy0">;</span>
<span class="re0">$data</span> <span class="sy0">=</span> <span class="re0">$cache</span><span class="sy0">-&amp;</span>gt<span class="sy0">;</span>get<span class="br0">&#40;</span> <span class="st_h">'auniqueidentifier'</span> <span class="br0">&#41;</span><span class="sy0">;</span>
<span class="re0">$cache</span><span class="sy0">-&amp;</span>gt<span class="sy0">;</span>remove<span class="br0">&#40;</span> <span class="st_h">'auniqueidentifier'</span> <span class="br0">&#41;</span><span class="sy0">;</span></pre></div></div></div></div></div></div></div>


<p>So, let&#8217;s go and make your TYPO3 extension fast! <img src="https://s.w.org/images/core/emoji/13.0.1/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
]]></content:encoded>
					
					<wfw:commentRss>https://aimeos.org/tips/how-to-use-the-typo3-caching-framework-with-cache-groups/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
