<?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>cache | Nerdpress.org</title>
	<atom:link href="https://nerdpress.org/tag/cache/feed/" rel="self" type="application/rss+xml" />
	<link>https://nerdpress.org</link>
	<description>...dev, tech problems and solutions.</description>
	<lastBuildDate>Fri, 04 May 2018 12:55:09 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
	<item>
		<title>Symfony Cache Component with SncRedisBundle</title>
		<link>https://nerdpress.org/2016/08/23/symfony-cache-component-sncredisbundle/</link>
		
		<dc:creator><![CDATA[Ivo Bathke]]></dc:creator>
		<pubDate>Tue, 23 Aug 2016 07:45:46 +0000</pubDate>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[cache]]></category>
		<category><![CDATA[redis]]></category>
		<guid isPermaLink="false">https://nerdpress.org/?p=2716</guid>

					<description><![CDATA[<p>Since version 3.1 there is a Cache component with a PSR-6 implementation integrated in Symfony. So we do not need to add a 3rd party lib as Doctrine Cache anymore when we need caching these days. Doctrine Cache does the job but by implementing a standard the Symfony Cache seems to have another advantage besides &#8230; </p>
<p class="link-more"><a href="https://nerdpress.org/2016/08/23/symfony-cache-component-sncredisbundle/" class="more-link">Continue reading<span class="screen-reader-text"> "Symfony Cache Component with SncRedisBundle"</span></a></p>
The post <a href="https://nerdpress.org/2016/08/23/symfony-cache-component-sncredisbundle/">Symfony Cache Component with SncRedisBundle</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></description>
										<content:encoded><![CDATA[<p>Since version 3.1 there is a Cache component with a <a href="http://www.php-fig.org/psr/psr-6/" target="_blank">PSR-6</a> implementation integrated in <a href="https://symfony.com/" target="_blank">Symfony</a>.<br />
So we do not need to add a 3rd party lib as <a href="https://github.com/doctrine/cache" target="_blank">Doctrine Cache</a> anymore when we need caching these days.</p>
<p>Doctrine Cache does the job but by implementing a standard the Symfony Cache seems to have another advantage besides its delievered anyway. So i checked it out.</p>
<p>Documentation is still a bit sparse and the best resource so far is this blogpost:<br />
<a href="https://symfony.com/blog/new-in-symfony-3-1-cache-component" target="_blank">https://symfony.com/blog/new-in-symfony-3-1-cache-component</a></p>
<p>I wont go into detail on how you use the Cache but rather how you integrate it with Redis, which is my favourite Cache backend.<br />
<span id="more-2716"></span></p>
<p>You can create a Cache service via the FrameworkBundle in your config.yml and you can also create a default Redis client to use with your Cache service.</p>
<pre class="brush: plain; title: ; notranslate">
framework:
    default_locale: de
    secret: ThisTokenIsNotSoSecretChangeIt
    assets: ~
    templating:
        engines: &#x5B;'twig']
    cache:
	default_redis_provider: &quot;redis://%cache.redis_host%:%cache.redis_port%/%cache:redis_db%&quot;
        pools:
           sf_cache:
             adapter: cache.adapter.redis
             public: true
             default_lifetime: 1200
             provider: cache.default_redis_provider
</pre>
<p>When the Redis Extension is present it will use the extension elsewards it will use Predis, which is plain PHP.<br />
You can also pass any other client. F.e. if you have already created a Predis client service in your app then just pass this as provider.</p>
<pre class="brush: plain; title: ; notranslate">
    cache:
        pools:
           sf_cache:
             adapter: cache.adapter.redis
             public: true
             default_lifetime: 1200
             provider: my.predis.client.service.id
</pre>
<p>I recently discovered <a href="https://github.com/snc/SncRedisBundle" target="_blank">SncRedisBundle</a> and i have to say i like it :)<br />
I used to create Predis clients directly because its very easy and thought i wouldnt need a bundle for this.<br />
But with SncRedisBundle you get Logging and WebProfiler support additionally, which is great for development.<br />
Also you get some more easy symfony integrations for other stuff as Doctrine, Mailings or Sessions which i dont use but maybe you do.<br />
So check it out.</p>
<p>So my best move is to use <a href="https://github.com/snc/SncRedisBundle" target="_blank">SncRedisBundle</a> to create a Redis client and integrate it with the Cache Component.</p>
<pre class="brush: plain; title: ; notranslate">
snc_redis:
    clients:
        sf_cache:
            type: predis
            alias: sf_cache
            dsn: &quot;redis://%cache.redis_host%:%cache.redis_port%/0&quot;
            logging: &quot;%kernel.debug%&quot;

framework:
    default_locale: de
    secret: ThisTokenIsNotSoSecretChangeIt
    assets: ~
    templating:
        engines: &#x5B;'twig']
    cache:
        pools:
           sf_cache:
             adapter: cache.adapter.redis
             public: true
             default_lifetime: 1200
             provider: snc_redis.sf_cache
</pre>
<p><a href="https://nerdpress.org/wp-content/uploads/2016/08/Bildschirmfoto-vom-2016-08-23-09-37-43.png"><img decoding="async" src="https://nerdpress.org/wp-content/uploads/2016/08/Bildschirmfoto-vom-2016-08-23-09-37-43-300x64.png" alt="Bildschirmfoto vom 2016-08-23 09-37-43" width="300" height="64" class="alignnone size-medium wp-image-2721" srcset="https://nerdpress.org/wp-content/uploads/2016/08/Bildschirmfoto-vom-2016-08-23-09-37-43-300x64.png 300w, https://nerdpress.org/wp-content/uploads/2016/08/Bildschirmfoto-vom-2016-08-23-09-37-43.png 501w" sizes="(max-width: 300px) 100vw, 300px" /></a></p>
<p>Now you have integrated caching with webprofiler appearance and logging, nice!</p>
<p><strong>UPDATE </strong><br />
You can also add your snc redis client to the standard app cache, provided with symfony:</p>
<pre class="brush: plain; title: ; notranslate">
cache:
    prefix_seed: my-app
    app: cache.adapter.redis
    system: cache.adapter.redis
    default_redis_provider: snc_redis.cache
</pre>The post <a href="https://nerdpress.org/2016/08/23/symfony-cache-component-sncredisbundle/">Symfony Cache Component with SncRedisBundle</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Caching Data in Symfony2</title>
		<link>https://nerdpress.org/2012/07/10/caching-data-in-symfony2/</link>
					<comments>https://nerdpress.org/2012/07/10/caching-data-in-symfony2/#comments</comments>
		
		<dc:creator><![CDATA[Ivo Bathke]]></dc:creator>
		<pubDate>Tue, 10 Jul 2012 10:19:01 +0000</pubDate>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[cache]]></category>
		<category><![CDATA[Symfony2]]></category>
		<guid isPermaLink="false">https://nerdpress.org/?p=2230</guid>

					<description><![CDATA[<p>Symfony2 has a great Caching Layer based on its HTTP Cache. But this aims mainly on caching the views. In some apps however you need to cache data behind the scenes, f.e. responses from API calls or custom objects sets. Symfony2 itself doesnt have such a functionality on first sight (symfony2 doesnt, but Doctrine, see &#8230; </p>
<p class="link-more"><a href="https://nerdpress.org/2012/07/10/caching-data-in-symfony2/" class="more-link">Continue reading<span class="screen-reader-text"> "Caching Data in Symfony2"</span></a></p>
The post <a href="https://nerdpress.org/2012/07/10/caching-data-in-symfony2/">Caching Data in Symfony2</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></description>
										<content:encoded><![CDATA[<p>Symfony2 has a great Caching Layer based on its <a href="http://symfony.com/doc/current/book/http_cache.html">HTTP Cache</a>. But this aims mainly on caching the views.</p>
<p>In some apps however you need to cache data behind the scenes, f.e. responses from API calls or custom objects sets.<br />
Symfony2 itself doesnt have such a functionality on first sight (symfony2 doesnt, but Doctrine, see below) and so I searched for one and first found a bundle which utilize the Zend Cache lib:<br />
<a href="https://github.com/KnpLabs/KnpZendCacheBundle">https://github.com/KnpLabs/KnpZendCacheBundle</a></p>
<p>This worked well but as discussed here(<a href="https://github.com/KnpLabs/KnpZendCacheBundle/issues/2">https://github.com/KnpLabs/KnpZendCacheBundle/issues/2</a>) this adds dependencies to your Symfony2 project.  This is actually not necessary since <a href="https://github.com/doctrine/common">Doctrine/Commons</a> is almost always part of your Symfony2 distribution and the Doctrine/Commons provides a Cache Layer as well.<br />
A very good one, indeed.</p>
<p>So if you need to cache data use <strong>Doctrine/Commons</strong>.<br />
<span id="more-2230"></span><br />
This Cache Layer abstracts the caching functionality and provides already various different backends for your caching data.<br />
These are already build-in in the master version:</p>
<ul>
<li>APC</li>
<li>Array</li>
<li>Filesystem</li>
<li>Memcache</li>
<li>PhpFile</li>
<li>Redis</li>
<li>WinCache</li>
<li>Xcache</li>
<li>ZendData</li>
</ul>
<p>You could even create your own on top of the <a href="https://github.com/doctrine/common/blob/master/lib/Doctrine/Common/Cache/CacheProvider.php">CacheProvider</a> class and the <a href="https://github.com/doctrine/common/blob/master/lib/Doctrine/Common/Cache/Cache.php">Cache</a> interface.</p>
<p>In your Symfony2 project simply register your cache service of choice and your ready to go.<br />
In your <em>config.yml</em> or <em>services.yml</em> add:<br />
<script src="https://gist.github.com/3082497.js?file=services.yml"></script><noscript><pre><code class="language-yaml yaml">cache:
        class: Doctrine\Common\Cache\PhpFileCache
        arguments: [%kernel.cache_dir%]</code></pre></noscript></p>
<p>And in your controller you can call the service and save and load data from the cache.</p>
<script src="https://gist.github.com/3082497.js?file=IndexController.php"></script><noscript><pre><code class="language-php php">$cache = $this-&gt;get(&#039;cache&#039;);
$cache-&gt;setNamespace(&#039;mynamespace.cache&#039;); 
if (false === ($cached_data = $cache-&gt;fetch($cache_key))) {
            $cached_data = $SOMEAPI-&gt;getData($params);
            $cache-&gt;save($cache_key, $cached_data, 3600);//TTL 1h
}</code></pre></noscript>
<p>As you can see you can set a namespace for your cache data, so that you can easy use it for different scenarions in the same app.<br />
Further you can set a time-to-live (TTL) in seconds as third parameter of the save method.</p>
<p>So after all symfony2 has a caching mechanism for data, its just a little hidden in the Doctrine/Commons dependency.</p>
<p><strong>Update from the Update!!</strong><br />
LiipDoctrineCacheBundle is abanndoned, use <a href="https://github.com/doctrine/DoctrineCacheBundle" target="_blank">https://github.com/doctrine/DoctrineCacheBundle</a><br />
<strong>Update!!</strong><br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p>I just was told that there is a Bundle for the Doctrine/Commons cache:<br />
<a href="https://github.com/liip/LiipDoctrineCacheBundle">https://github.com/liip/LiipDoctrineCacheBundle</a></p>
<p>So I recommend to use this.<br />
The benefit of this is, you can configure your caches through yml files and you have one central cache reference. I guess this saves some bytes in case you use different caches with different namepaces.</p>
<p>So with the LiipDoctrineCacheBundle the above example would go like this (given you have already registered the bundle):</p>
<p>config.yml<br />
<script src="https://gist.github.com/3205828.js?file=config.yml"></script><noscript><pre><code class="language-yaml yaml">liip_doctrine_cache:
    namespaces:
        mynamespace:
            namespace: mynamespace.cache
            type: php_file</code></pre></noscript></p>
<p>IndexController.php<br />
<script src="https://gist.github.com/3205828.js?file=IndexController.php"></script><noscript><pre><code class="language-php php">$cache = $container-&gt;get(&#039;liip_doctrine_cache.ns.[mynamespace]&#039;);
if (false === ($cached_data = $cache-&gt;fetch($cache_key))) {
            $cached_data = $SOMEAPI-&gt;getData($params);
            $cache-&gt;save($cache_key, $cached_data, 3600);//TTL 1h
}</code></pre></noscript></p>The post <a href="https://nerdpress.org/2012/07/10/caching-data-in-symfony2/">Caching Data in Symfony2</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></content:encoded>
					
					<wfw:commentRss>https://nerdpress.org/2012/07/10/caching-data-in-symfony2/feed/</wfw:commentRss>
			<slash:comments>7</slash:comments>
		
		
			</item>
		<item>
		<title>how to not cache the footer in magento</title>
		<link>https://nerdpress.org/2011/10/04/how-to-not-cache-the-footer-in-magento/</link>
					<comments>https://nerdpress.org/2011/10/04/how-to-not-cache-the-footer-in-magento/#comments</comments>
		
		<dc:creator><![CDATA[Max Girkens]]></dc:creator>
		<pubDate>Tue, 04 Oct 2011 03:10:45 +0000</pubDate>
				<category><![CDATA[eCommerce]]></category>
		<category><![CDATA[magento]]></category>
		<category><![CDATA[cache]]></category>
		<category><![CDATA[footer]]></category>
		<guid isPermaLink="false">https://nerdpress.org/?p=1823</guid>

					<description><![CDATA[<p>With some advanced scheduled-post-voodoo i successfully managed to publish this post already yesterday with some completely unrelated queries and no text. this was not intended &#8211; please accept my apologies :P Anyway: In the footer of my magento shop we might have a summary of the shopping cart, which i simply put in the footer.phtml &#8230; </p>
<p class="link-more"><a href="https://nerdpress.org/2011/10/04/how-to-not-cache-the-footer-in-magento/" class="more-link">Continue reading<span class="screen-reader-text"> "how to not cache the footer in magento"</span></a></p>
The post <a href="https://nerdpress.org/2011/10/04/how-to-not-cache-the-footer-in-magento/">how to not cache the footer in magento</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></description>
										<content:encoded><![CDATA[<p>With some advanced scheduled-post-voodoo i successfully managed to publish this post already yesterday with some completely unrelated queries and no text. this was not intended &#8211; please accept my apologies :P</p>
<p>Anyway: In the footer of my magento shop we might have a summary of the shopping cart,<br />
which i simply put in the footer.phtml template file:<br />
<span id="more-1823"></span></p>
<pre class="brush: php; title: ; notranslate">
&lt;?php if (Mage::getModel('checkout/cart')-&gt;getItemsCount() &gt; 0): ?&gt;
  &lt;div class=&quot;footer_cart_widget&quot;&gt;
    &lt;a href=&quot;/checkout/cart&quot; class=&quot;cart&quot;&gt;
      &lt;?php echo $this-&gt;__('Warenkorb') ?&gt;:&lt;br /&gt;
      &lt;span class=&quot;cart_meta&quot;&gt;
        &lt;?php echo Mage::getModel('checkout/cart')-&gt;getItemsCount() ?&gt;
        &lt;?php if (Mage::getModel('checkout/cart')-&gt;getItemsCount() == 1): ?&gt;
          Produkt: 
        &lt;?php else: ?&gt;
          Produkte: 
        &lt;?php endif; ?&gt;
        &lt;?php echo $this-&gt;helper('checkout')-&gt;formatPrice(Mage::getSingleton('checkout/cart')-&gt;getQuote()-&gt;getGrandTotal()); ?&gt;
      &lt;/span&gt;
    &lt;/a&gt;
  &lt;/div&gt;
&lt;?php endif; ?&gt;
</pre>
<p><a href="https://nerdpress.org/wp-content/uploads/2011/10/Bildschirmfoto-2011-10-04-um-21.21.05.png"><img decoding="async" src="https://nerdpress.org/wp-content/uploads/2011/10/Bildschirmfoto-2011-10-04-um-21.21.05-300x146.png" alt="Magento Footer Shopping cart Widget disable cache" title="Magento Footer Shopping Cart Summary" width="300" height="146" class="alignnone size-medium wp-image-1846" srcset="https://nerdpress.org/wp-content/uploads/2011/10/Bildschirmfoto-2011-10-04-um-21.21.05-300x146.png 300w, https://nerdpress.org/wp-content/uploads/2011/10/Bildschirmfoto-2011-10-04-um-21.21.05.png 443w" sizes="(max-width: 300px) 100vw, 300px" /></a></p>
<p>This means we might need to disable the caching for the footer HTML block,<br />
so that my cart summary will stay dynamically generated.</p>
<p>This is how you can do it:</p>
<p>copy</p>
<pre class="brush: bash; title: ; notranslate">app/code/core/Mage/Page/Block/Html/Footer.php</pre>
<p>to</p>
<pre class="brush: bash; title: ; notranslate">app/code/local/Mage/Page/Block/Html/Footer.php</pre>
<p>and just comment out the following lines:</p>
<pre class="brush: php; title: ; notranslate">
//$this-&gt;addData(array(
//    'cache_lifetime'=&gt; false,
//    'cache_tags'    =&gt; array(Mage_Core_Model_Store::CACHE_TAG, Mage_Cms_Model_Block::CACHE_TAG)
//));
</pre>
<p>you could also put the cart values in the getCacheKeyInfo() method, but as this would result in caching a footer for any state of the shopping cart from my understanding, i don&#8217;t think it&#8217;s necessarily a good idea.</p>The post <a href="https://nerdpress.org/2011/10/04/how-to-not-cache-the-footer-in-magento/">how to not cache the footer in magento</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></content:encoded>
					
					<wfw:commentRss>https://nerdpress.org/2011/10/04/how-to-not-cache-the-footer-in-magento/feed/</wfw:commentRss>
			<slash:comments>6</slash:comments>
		
		
			</item>
	</channel>
</rss>
