2

I'm using the new Symfony Cache Component. I generate my cache first with a command (Command/AppCacheGenerateCommand.php):

$cache = new FilesystemAdapter();         
foreach ($domains as $domain){
        if ($domain->getHost()){
            $output->writeln('Generate cache for domain: ' . $domain->getHost());
            $domainCache = $cache->getItem('domain.' . $domain->getHost());
            $domainCache->set($domain->getId());
            $cache->save($domainCache);
        }
    }

Then trying to get these cached elements in a onKernelRequest EventListener (EventListener/RequestListener.php)

$cache = new FileSystemAdapter();
    $domainCache = $cache->getItem('domain.' . $host);
    if (!$domainCache->isHit()){
        die;
    }

It's always dies here, not going further. Anyone can give me an explanation? (I've tried if the host not matching, but it does...)

1
  • You have to add an answer with the solution (and then accept it) and NOT as update inside your question. Take a look at the Help Center! Commented Nov 26, 2016 at 21:37

1 Answer 1

4

I've figured out the answer:

First I had to add cache config in config.yml:

framework:
    cache:
        pools:
            my_cache_name:
                adapter: cache.adapter.filesystem
                default_lifetime: 0

Than instead of

$cache = new FilesystemAdapter(); 

I had to use the new service like:

$cache = $this->getContainer()->get('my_cache_name);

And it's started working! Hope it helps to others!

Sign up to request clarification or add additional context in comments.

2 Comments

You have to add the answer here and NOT as update inside your question. Take a look at the Help Center section or at the thousand of questions with an accepted Answer here on StackOverflow to got it.
Please take note of @gp_sflover's advice. Use answers for answers and questions for questions. It's as simple as that. I've done it now for you, But save others time, the next time. Cheers

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.