Skip to content

Instantly share code, notes, and snippets.

@peterjmit
Created March 6, 2012 17:47
Show Gist options
  • Select an option

  • Save peterjmit/1987713 to your computer and use it in GitHub Desktop.

Select an option

Save peterjmit/1987713 to your computer and use it in GitHub Desktop.

Revisions

  1. peterjmit revised this gist Mar 6, 2012. 1 changed file with 5 additions and 1 deletion.
    6 changes: 5 additions & 1 deletion doctrine_cache_driver.php
    Original file line number Diff line number Diff line change
    @@ -31,4 +31,8 @@ public function saveToCache($item_to_save)
    {
    $this->getCacheDriver()->save('foo_key', $item_to_save);
    }
    }
    }

    $foo = new Foo($doctrine_entity_manager);

    $foo->saveToCache('bar');
  2. peterjmit revised this gist Mar 6, 2012. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions doctrine_cache_driver.php
    Original file line number Diff line number Diff line change
    @@ -23,6 +23,10 @@ public function getCacheDriver()
    return $this->_em->getConfiguration()->getResultCacheImpl();
    }

    /**
    * Example usage of Foo::getCacheDriver
    *
    */
    public function saveToCache($item_to_save)
    {
    $this->getCacheDriver()->save('foo_key', $item_to_save);
  3. peterjmit created this gist Mar 6, 2012.
    30 changes: 30 additions & 0 deletions doctrine_cache_driver.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    <?php

    class Foo
    {
    private $_em;

    public function __construct($entity_manager)
    {
    $this->_em = $entityManager;
    }

    /**
    * I couldn't find any where in the Doctrine or Symfony docs that explained
    * how to get the Cache Driver defined in my config_prod.yml file for use
    * in saving custom arrays/keys.
    *
    * (Rather than directly instantiating a cache driver i.e. $cacheDriver = new \Doctrine\Common\Cache\ApcCache())
    *
    * @return Implementation of Doctrine\Common\Cache\Cache (APC/Xcache etc.)
    */
    public function getCacheDriver()
    {
    return $this->_em->getConfiguration()->getResultCacheImpl();
    }

    public function saveToCache($item_to_save)
    {
    $this->getCacheDriver()->save('foo_key', $item_to_save);
    }
    }