Last active
August 29, 2015 13:56
-
-
Save liuggio/9300513 to your computer and use it in GitHub Desktop.
caches
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
doctrine: | |
orm: | |
metadata_cache_driver: apc # annotation | |
query_cache_driver: redis # dql parsed in sql | |
result_cache_driver: redis # query result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if (!$data = $this->get('my_cache')->fetch('foo')) { | |
$data = $this->doSomeHeavyCalculation(); | |
$this->get('my_cache')->store('foo', $data) | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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. | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// $query = $this->createQueryBuilder ... | |
$query->useResultCache(true, $lifetime); | |
$query->useQueryCache(); | |
// $products = $query->getResult(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
services: | |
my_cache: | |
class : Doctrine\Common\Cache\Apc | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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’ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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