Skip to content

Instantly share code, notes, and snippets.

@liuggio
Last active August 29, 2015 13:56
Show Gist options
  • Save liuggio/9300513 to your computer and use it in GitHub Desktop.
Save liuggio/9300513 to your computer and use it in GitHub Desktop.
caches
doctrine:
orm:
metadata_cache_driver: apc # annotation
query_cache_driver: redis # dql parsed in sql
result_cache_driver: redis # query result
<?php
if (!$data = $this->get('my_cache')->fetch('foo')) {
$data = $this->doSomeHeavyCalculation();
$this->get('my_cache')->store('foo', $data)
}
<?php
$cache = new ApcCache();
$cache->setNamespace('Hydratation');
// or using LiipDoctrineCacheBundle
$cache = $container->get('liip_doctrine_cache.ns.[your_name]');
// setHydration
$query->setHydrationCacheProfile(new QueryCacheProfile($ttl, null, $cache));
<?php
namespace Acme\Foo;
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;
class FooCacheWarmer implements CacheWarmerInterface
{
public function isOptional()
{
return false;
}
public function warmUp($cacheDir)
{
// do the magic here.
}
}
<?php
// $query = $this->createQueryBuilder ...
$query->useResultCache(true, $lifetime);
$query->useQueryCache();
// $products = $query->getResult();
services:
my_cache:
class : Doctrine\Common\Cache\Apc
<?php
// $article is already managed or loaded
// we are changing the Headline
$article->setHeadline('I love PUG Roma');
$em->flush();
echo $article->getHeadline(); // is ‘I love PUG Roma’
<?php
$article = new Article();
$article->setHeadline('I love SymfonyDay');
$em->persist($article); // the entity is managed
$em->flush(); // the entity is persisted
$article->setHeadline('I love SymfonyDay portugal');
$em->persist($article); // don't needed is already managed
$em->flush(); // the Headline is updated on the persistence layer
<?php
$article = $em->find(Article, 1234);
$article->setHeadline('I love SymfonyDay');
$article2 = $em->find(Article, 1234);
echo $article2->getHeadline(); // 'I love SymfonyDay'
if ($article === $article2) ---> true!!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment