PHP code example of bigpaulie / cachebundle

1. Go to this page and download the library: Download bigpaulie/cachebundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

bigpaulie / cachebundle example snippets


$bundles = array(
        ...
        new bigpaulie\CacheBundle\BigpaulieCacheBundle(),
);

// $qb instanceof QueryBuilder

$qb->select('u')
   ->from('User', 'u')
   ->where('u.id = ?1')
   ->orderBy('u.name', 'ASC')
   ->setParameter(1, 100);
   
$query = $qb->getQuery();
$query->setQueryCaching(true);

$result = $query->getResult();

$query->setQueryCaching(true, 3600, 'my_unique_key');

use bigpaulie\CacheBundle\Doctrine\Support\Cacheable;

 find($id, $lifetime = null, \Closure $callable = null)

findOneBy(array $criteria, array $orderBy = null, $lifetime = null, \Closure $callable = null)

findAll($lifetime = null, \Closure $callable = null)

use bigpaulie\CacheBundle\Doctrine\Support\Cacheable;
use Doctrine\ORM\EntityRepository;

/**
 * SomeRepository
 *
 * This class was generated by the Doctrine ORM. Add your own custom
 * repository methods below.
 */
class SomeRepository extends EntityRepository
{
    use Cacheable;
}

// No caching
$this->getDoctrine()->getRepository('SomeBundle:SomeEntity')->find(1);

// Caching for 3600 seconds
$this->getDoctrine()->getRepository('SomeBundle:SomeEntity')->find(1, 3600);

// Caching for 3600 seconds and passing a Closure
$this->getDoctrine()->getRepository('SomeBundle:SomeEntity')->find(1, 3600, function () {
    return new NullObject();
});