PHP code example of intaro / memcached-tags-bundle
1. Go to this page and download the library: Download intaro/memcached-tags-bundle 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/ */
intaro / memcached-tags-bundle example snippets
// app/AppKernel.php
public function registerBundles()
{
$bundles = array(
new Intaro\MemcachedTagsBundle\IntaroMemcachedTagsBundle(),
);
}
$em = $container->get('doctrine')->getManager();
$em->createQuery('SELECT book FROM AcmeHelloBundle:Book book', 3600, [
'Acme\HelloBundle\Entity\Book'
]);
$em = $container->get('doctrine')->getManager();
$builder = $em->createQueryBuilder()
->select('book')->from('AcmeHelloBundle:Book', 'book')
->useResultCache(true, 3600) //enable result cache and set cache life time
->setCacheTags(['Acme\HelloBundle\Entity\Book'])
->join('book.author', 'author')
->addCacheTag('Acme\HelloBundle\Entity\Author');
if ($disableTags) {
$builder->clearCacheTags();
}
$builder->getQuery()->getResult();
$em = $container->get('doctrine')->getManager();
$em->getRepository('AcmeHelloBundle:Book')->clearEntityCache();
// or
$em->tagsClear('Acme\HelloBundle\Entity\Book');
$book = $em->getRepository('AcmeHelloBundle:Book')->find($id);
$em->getRepository('AcmeHelloBundle:Book')->clearEntityCache($book->getId());
// or
$em->tagsClear('Acme\HelloBundle\Entity\Book[id="' . $book->getId() . '"]');
$em = $container->get('doctrine')->getManager();
$book = $em->getRepository('AcmeHelloBundle:Book')->find(25);
$book->setName('New book');
$em->merge($book);
$em->flush();
// Tags Acme\HelloBundle\Entity\Book and Acme\HelloBundle\Entity\Book[id="25"] are cleared
use Intaro\MemcachedTagsBundle\Doctrine\Annotation\AssociationCache;
/**
* @ORM\Entity
* @ORM\Table(name="shelf")
* @AssociationCache(lifetime=100)
*/
class Shelf
{
...
}
/**
* @ORM\Entity
* @ORM\Table(name="shelf")
* @AssociationCache(lifetime=100, tags={"Acme\HelloBundle\Entity\Author", "Acme\HelloBundle\Entity\Book"})
*/
class Author
{
...
}
$em = $container->get('doctrine')->getManager();
$book = $em->getRepository('AcmeHelloBundle:Book')->find(25);
$shelf = $book->getShelf();
// Cache with tag Acme\HelloBundle\Entity\Shelf[id="13"] will be loaded
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.