Symfony 2 and Twig cache — are they the same? - php

My question is are the Symfony 2 cache mechanism and Twig cache mechanism the same?
Lets say I decide to use Twig in my MVC framework, would I have the same cache mechanism Symfony 2 uses? I know both Symfony2 and Twig are created by Fabien. But I dont know is Symfony 2 using only Twig cache or is there something more?
So I hope you understand the question. Does Symfony 2 uses Twig for cache? And if not, what are the differences between Symfony 2 and Twig caching?

unsure of the full answer, but symfony and twig must use separate caching mechanisms as you are not forced to use twig in symfony and yet cache still works. for more info check http://symfony.com/doc/current/ and dig into the code.
Edit:
To expand on my non-answer above. Twig cache is really a compilation cache. Your templates are saved as php files. To quote F. Potencier "[...] Twig caches the compiled templates to avoid the parsing phase for sub-sequent requests. [...]" (source)
While Symfony cache is (as has already been mentioned) a HTTP cache and is extensively explained in Symfony Docs cache section
Hope this helps.

Symfony 2 uses HTTP cache for caching purposes. And Twig cache is joust caching of Twig templates, so they don't have to recompile on every request. So Twig caching only ensures templates are compiled once on first request.
And Symfony 2 HTTP cache is another beast :) It provides abstraction around HTTP Cache mechanism and so you can cache using HTTP Cache headers etc...
So the short answer is NO! They are not the same!

No, they are not the same. Symfony caches a lot of stuff like routes, translations, the container, etc; Twig just caches templates by compiling them down to PHP classes. Of course, Twig's caching system works in a Symfony app as well.

Related

Redis for silverstripe 4 caching

I am using SilverStripe 4.2.2.
Wondering how could I configure Redis for caching in SilverStripe 4?
Take a look at pstaender/silverstripe-redis-cache which should make it a lot easier to get started with SilverStripe 4 and Redis right off the bat (since it implements CacheFactory and offers some configuration for SilverStripe). Also nice that it also uses predis, similar to Symfony's cache component noted above.
This happens to be ideal for me as well since one of my primary reasons for using Redis would be for template caching distributed across a cluster. 🙂

Output Cache and Redis?

I'm trying to implement the whole page cache in my website. (Just like stackoverflow). I have already implemented the Output Cache, but my friend told me that stackoverflow uses redis as their cache layer and I'm confused about the redis part.
Is redis the same as outputcache? Can I implement outputcache by using redis? (For yii developers, I'm using Yii's outputcache).
Thanks!
Yii's output cache will store the cached content using the active cache component, which can be CDummyCache/CDbCache/CApcCache/CFileCache/CMemCache, etc(what you set in the config file under the components area).
As it stands right now, there is no official CRedisCache component, but there is this extension: http://www.yiiframework.com/extension/rediscache/ which might help you.
Also, since Redis is key/value store and a bit more(though you won't use that bit more at all i guess) you can give CMemCache a try(having in mind you have memcache php extension and memcached daemon installed on your server).
L.E: i also found this for you: https://github.com/phpnode/YiiRedis which seems very neat.

APC as a session handler using Symfony components

I'm using Symfony components in my web application. I need to store session in APC but unfortunatelly I can't find the way to do it.
As I see here Symfony does not support APC as a session handler. Is that true?
I have found an old example of using APC as a session handler in Symfony. But there all configuration is done in factories.yml file which I don't have since I'm only using standalone Symfony components.
Can anyone give me an example of using APC as a session handler using only Symfony components?
Since I don't get any answer here for a long time I will answer the question myself. For now there is no built in suport for APC as a session handler in Symphony framework. There is no particlar reason for it, likely Symphony developers just did not get to it.
The solution is simple, just code APCSessionHandler.php file yourself (I was not doing it because we decided not use this in project), APCSessionHandler will be very similar to MemcachedSessionHandler.php file.
How to store PHP sessions in APC Cache? suggests it is feasible but a bad idea for a busy site. The accepted answer lists a few useful ideas

Symfony2 Application Parses YML On Every Request

My Symfony2 application has some performance problems, so I ran a webgrind on it in order to see what was happening. Turns out it was parsing huge amounts of YML files on every request and I can't figure out why. I already have APC caching enabled so I don't know what it could be. Any help with this issue would be much appreciated.
Edit: Here is a screenshot of the webgrind I ran.
From my research, it appears that the APCClassLoader does not cause Symfony2 to cache the YAML files used in Doctrine. It appears to cache the configuration files by default (config.yml, parameters.yml), but the actual ORM YAML files used by Doctrine are not cached unless you specify a cache driver as shown in the documentation linked below:
http://symfony.com/doc/2.3/reference/configuration/doctrine.html#caching-drivers
So, it's possible that the solution above solved the issue if the poster had only configuration YAML and not doctrine YAML. However, if Doctrine YAML is involved, a Doctrine cache driver must be specified.
This also affects people using Annotations as they will be parsed on each page load unless a cache driver is specified (other than the Doctrine default array cache).
Thought I should post because this is a complex issue and the answer above was misleading in my case where Doctrine ORM YAML files were the source of the caching issue.
This post has more details on my specific issue and the resolution:
Why is Symfony2 app spending 70-90% of its time parsing YAML?
Figured out what was going on. I had APC enabled and working, but wasn't using the ApcUniversalClassLoader in my autoload.php. More details here. When they say in the docs "suggestions" for improved performance they really mean "you have to do this or your performance will be terrible."

Symfony 2: Disable Monolog

Is it possible to disable core bundles of Symfony 2, such as the Monolog logger?
I am working on an application which doesn't have many fancy requirements except that it should be ultra fast and as much lightweight as possible. I guess Symfony 2 is not the best framework to go with in my situation, but for me it uses the best principles there are, it is a pleasure to work with and also there are many bundles I might take advantage of later on.
So, my question is as in the title, is it possible to completely disable logging (in the production environment at least), and if it is, would it be possible to disable other such features as well?
P.S.: I understand that the easiest and cleanest way to disable a bundle is to remove it from the kernel, but what happens with the code which uses it?
Actually, Symfony2 is perfect for what you want. As it is a decoupled framework, you can just include the features you want. You can disable monolog from config files.
Also, there is Silex, a micro-framework built with Symfony components, designed to be lightweight and fast for relatively small jobs.

Categories