08.
Caching in the prod Environment Only
Keep on Learning!
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
Whoops, an error! Please, try again later.
11 Comments
Hi, in my config.yml there is no doctrine cache section. It stops at spool: {type: memory}
If I write it in that place it shows me:
What I'm missing?
thank you
Hey Josh,
Have you properly installed this bundle, i.e. download it with Composer and register this bundle in AppKernel? Please, double check it. We did all the installation and configuration of it here: https://knpuniversity.com/s... . Also, try to clear the cache.
Cheers!
I've just noticed that by accident I started this course after the first videos. Now, I started from the beginning and it's everything ok, thank you.
Setting the doctrine_cache type to array to "stop logging" is pretty ugly. Why would there not be an "enabled" flag?
Hey Richie Hamburg!
Ah, great question! The point of this configuration is that this will create a "cache" service for us - specifically this creates
doctrine_cache.providers.my_markdown_cache. We're then referencing and using this service in our code. So, one way or another, we DO need this service to always exist... which means that in dev environment, we need this service to exist... but not actually to do any real caching. By setting the type toarrayit effectively means "create a cache object, but of a type that doesn't actually cache". But I totally hear you - the bundle (DoctrineCacheBundle) could have setup their configuration so that, instead of atype: array, you could set someenabled: falseflag, and behind the scenes, this would switch you to the "array" type automatically (or to the "void" type - which truly caches nothing - the array type at least "caches" within a process, so that if you ask for a value 2 times, it only calculates it once). It's just a matter of taste - I like theenabled: falseidea, but also, since that would change the type behind-the-scenes, thetype: arrayortype: voidmight be clearer to some people!Cheers!
Hi, Team knpuniversity.com. You may hear more from me because I'm working through the Symfony3 courses with the ultimate goal of starting work on a project in Symfony4, so I'll be around here for a while....
When I get about a minute into this video, the step to refresh the prod page (http://localhost:8000/app.php/genus/octopus) results in a 500 error. The dev side works fine. Here's the error from the server log:
[2018-01-29 00:42:18] request.CRITICAL: Uncaught PHP Exception Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException: "You have requested a non-existent service "doctrine_cache.providers.my_markdown_cache"." at D:\Users\c\src\ctr-symfony3-fundamentals\var\bootstrap.php.cache line 2129 {"exception":"[object] (Symfony\\Component\\DependencyInjection\\Exception\\ServiceNotFoundException(code: 0): You have requested a non-existent service \"doctrine_cache.providers.my_markdown_cache\". at D:\\Users\\c\\src\\ctr-symfony3-fundamentals\\var\\bootstrap.php.cache:2129)"} []
Can you help me figure out what's causing this? I've tried duplicating the code for the caching in config.yml to config_prod.yml as a last resort to make sure the service wasn't missing, but that didn't help so I removed it. I'm using the composer.json from the course download, so Symfony 3.1.4 on PHP 7.2.1, and I'm using the server:run command to execute the code.
Thank you!
Hey Chris R
We are happy to hear from you :)
I believe you just need to clear cache for your prod environment. Prod environment caches a lot of things and you have to manually specify whenever you want to clear it ($ php bin/console cache:clear -e prod)
If that's not the case, let us know! Have a nice day
That did it, thanks!
Why do I get this warning when clearing the cache?
[WARNING] Calling cache:clear without the --no-warmup option is deprecated since version 3.3. Cache warmup should be
done with the cache:warmup command instead.
Hey Jeroen,
You get this warning because cache:clear command will only clear the cache in Symfony 4.0. For now, this command clear the cache and then warm it up. So the correct way for Symfony 3.3 is:
and you won't get this warning anymore.
But since Symfony 4.0 you can just do:
Because cache:clear won't warm up the cache anymore.
Cheers!
allright, thanks!
"Houston: no signs of life"
Start the conversation!