21.07.2015
Slides dispo à cette addresse :
http://bit.ly/1JsmOMw
Cyril Souillard
Architecte Web en Freelance
@CyrilSouillard
Cache driver intégré à Doctrine
LswMemcacheBundle:
lsw_memcache:
pools:
default:
servers:
- { host: 10.0.0.1, tcp_port: 11211, weight: 15 }
- { host: 10.0.0.2, tcp_port: 11211, weight: 30 }
options:
allow_failover: true
max_failover_attempts: 20
session_redundancy: 2
compress_threshold: 20000
lock_timeout: 15
# a lot of other usefull things ;)
sessions:
servers:
- { host: localhost, tcp_port: 11212 }
session:
pool: sessions
doctrine:
result_cache:
pool: default
entity_manager: [default, read]
prefix: "result_"
Configuration
#DemoRepository
public function findAll()
{
$qBuilder = $this->em->getManager()
->createQueryBuilder()
->select('d')
->from('AppBundle:Demo', "d");
$data = $qBuilder->getQuery()
->useResultCache(true, 3600, 'mySuperCacheKey')
->getResult();
return $data;
}
mise en pace dans un Repository
public function __construct($memcacheService)
{
$this->memcache = $memcacheService;
}
public function getMyData()
{
if(($result = $this->memcache->get('myDataResult')) === false){
// do whatever you want to get the result.
$this->memcache->set('myDataResult', $result, 0, 3600);
}
return $result;
}
mise en pace via le service
Invalidation de cache
There are only two hard things in Computer Science: cache invalidation and naming things. Phil Karlton
Proscrire les traitements à partir
de collections cachés