Search code examples
phpsymfonyapc

Notice: apc_fetch(): Unexpected end of serialized data


I'm tring to cache a list of categories for a forum.

I've this error : ContextErrorException: Notice: apc_fetch(): Unexpected end of serialized data in C:\wamp\www\project\vendor\doctrine\cache\lib\Doctrine\Common\Cache\ApcCache.php line 40

The controller:

<?php
namespace Acme\ForumBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Doctrine\Common\Cache\ApcCache;

class DefaultController extends Controller
{
    public function sidebarAction($slug = null)
    {
        $cache = new ApcCache;

        if($cache->contains('ListOfCategories')) {
            $categories = $cache->fetch('ListOfCategories');
        } else {
            $categories = $this->getDoctrine()
                                ->getManager()
                                ->getRepository('AcmeForumBundle:Category')
                                ->getCategories();
            $cache->save('ListOfCategories', $categories, 500);
        }

        return $this->render('AcmeForumBundle:Block:sidebar.html.twig', array(
            'slug'       => $slug,
            'categories' => $categories
        ));
    }
}

My config.yml:

# Doctrine Configuration
doctrine:
    dbal:
        driver:   "%database_driver%"
        host:     "%database_host%"
        port:     "%database_port%"
        dbname:   "%database_name%"
        user:     "%database_user%"
        password: "%database_password%"
        charset:  UTF8
        # if using pdo_sqlite as your database driver, add the path in parameters.yml
        # e.g. database_path: "%kernel.root_dir%/data/data.db3"
        # path:     "%database_path%"

    orm:
        auto_generate_proxy_classes: "%kernel.debug%"
        auto_mapping: true
        query_cache_driver:    apc
        metadata_cache_driver: apc

For this line: metadata_cache_driver: apc I'm not sure if it's required.

My APC configuration:

[APC]
apc.enabled = 1
apc.shm_size = 256M
apc.max_file_size = 5M
apc.stat = 1

What I did wrong ?

PS: APC is correctly installed, phpinfo(); confirm

Thanks


Solution

  • I found an other way :

    config.yml

    orm:
        auto_generate_proxy_classes: "%kernel.debug%"
        auto_mapping: true
        metadata_cache_driver: apc
        result_cache_driver: apc
        query_cache_driver: apc
    

    Repository :

    <?php
    
    namespace xxxxxx\ForumBundle\Entity;
    
    use Doctrine\ORM\EntityRepository;
    
    /**
     * CategoryRepository
     *
     * This class was generated by the Doctrine ORM. Add your own custom
     * repository methods below.
     */
    class CategoryRepository extends EntityRepository
    {
        public function getCategories() {
    
            $q = $this->createQueryBuilder('c')
                      ->orderBy('c.weight', 'ASC');
    
            $query = $q->getQuery();
    
            $query->useResultCache(true, 300, 'list_of_categories');
    
            return $query->getResult();
        }
    }
    

    and remove all "apc line" in the controller