title: How to approach caching in ZF2
body: <p>I am just starting to get my head into caching as a whole. I have a simple indexAction() that fetches all given Datasets. My approach is:</p>
  
  <ul>
  <li>check for existing key 'controllername-index-index'</li>
  <li>if existing: return the value of the key</li>
  <li>if <strong>not</strong> existing, do the normal action and add the key</li>
  </ul>
  
  <p>The value inside the key should be the ViewModel that will be generated and populated with my data. </p>
  
  <p>Here's what i have done so far:</p>
  
  <pre><code>&lt;?php
  public function indexAction()
  {
      $sl = $this-&gt;getServiceLocator();
  //  $cache = $sl-&gt;get('cache');
  //  $key = 'kennzahlen-index-index';
  //
  //  if ($cache-&gt;hasItem($key)) {
  //      return $cache-&gt;getItem($key);
  //  }
  
      $viewModel = new ViewModel();
      $viewModel-&gt;setTemplate('kennzahlen/index/index');
      $entityService = $sl-&gt;get('kennzahlen_referenzwert_service');
      $viewModel-&gt;setVariable('entities', $entityService-&gt;findAll());
  
  //  $cache-&gt;setItem($key, $viewModel);
  
      return $viewModel;
  }
  </code></pre>
  
  <p>The Caching parts are commented out for testing purposes, but basically this is all that i am doing. The Caching config/service looks like the following:</p>
  
  <pre><code>&lt;?php
  'cache' =&gt; function () {
      return \Zend\Cache\StorageFactory::factory(array(
          'adapter' =&gt; array(
              'name' =&gt; 'filesystem',
              'options' =&gt; array(
                  'cache_dir' =&gt; __DIR__ . '/../../data/cache',
                  'ttl' =&gt; 100
              ),
          ),
          'plugins' =&gt; array(
              array(
                  'name' =&gt; 'serializer',
                  'options' =&gt; array(
  
                  )
              )
          )
      ));
  },
  </code></pre>
  
  <p>The serialization and caching works quite well, but i am surprised by the missing results. Going by what the ZendDevelopersToolbar tells me, the times WITHOUT caching range between 1.8s to 2.5s. Having the caching parts uncommented (enabled) doesn't really improve the loading time of my page at all.</p>
  
  <p>So my question is: Is this approach completely wrong? Are there different, more speedy parts, that can be saved with some neat configuration tricks?</p>
  
  <p>I Feel that a 2 second load time of a page is DEFINITELY too slow. 1s to me is the maximum given a huge amount of data, but certainly not anything more than that :S</p>
  
  <p>All help/hints/suggestions will be greatly appreciated. Thanks in advance!</p>