Redis for silverstripe 4 caching - php

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. 🙂

Related

Can I use a cut-down Laravel for API development?

I'm using Laravel for developing my API, but I was curious if there is a way to boost the performance even more by disable the things I don't need.
Like the CommandBus and the services which Laravel uses to render the views itself, because I'm only returning JSON and not using the features like CommandBus, view rendering etc.
Not as far as I know, but the easiest thing to do to speed up your application would be to use route caching in Laravel 5.
Other than that, I guess general tips would be:
Use nginx instead of Apache
Use Myisam intead of innodb (if you're using MySQL and only doing reads)
Read/write master slave configuration to do reads from the slave.
What response time are you getting and what is the response time that you would like?

Using local cache along with Doctrine ORM

I was working with Silex and Doctrine ORM. To make my database queries faster, I wanted to have a caching of some sort.
I looked at PhpFastCache - which provides a good caching framework - but does not really integrate with Doctrine. The best part about this is that I can have a local cache independent of any external service - like memcached. Since I have a small site which is hosted on shared host, I cannot spend money on having a service on cloud.
I also looked at existing cache providers for Doctrine ORM and all of them use external cache service.
The last thing I know I would have to do is write a provider myself using the PhpFastCache, but just wanted to make sure that there is no alternative online that I can use. I have tried my best by searching online all day today, but I just wanted to make sure.
Just to add: I have looked at APC and Memcache, but I have my site on shared hosting, and I would need a dedicated hosting for installing the PECL modules for APC/Memcache :(.
Doctrine includes quite a few cache drivers that do not seem to be documented. There is not one for PhpFastCache, but there are two that cache directly to the filesystem. Check out FilesystemCache and PhpFileCache. You can see the full list in the repository.
If I had to guess, I'd say that FilesystemCache is what you want. It stores serialized data in a plain file. PhpFileCache stores it as a PHP file, and then uses include to read it later. That means it has to be parsed by PHP on read, which is probably slower unless you use a PHP bytecode cache like APC.
Neither solution will be as fast as something like Memcache since they both read from the filesystem instead of memory, but they should provide an optimization for slow database queries that are run often.
Edit: As Kiran Madipally pointed out, it should be easy create your own PhpFastCache driver by extending CacheProvider.
I quickly wrote a provider for PhpFastCache. I have added the gist here:
https://gist.github.com/thephoenics/ee7de9f95bfdf5f6c24f

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.

Laravel 4 how to lazy load controllers?

Recently I've discovered that Laravel 4 is including all the controllers on each request regardless if it needs it or not, even though Composer has the whole controller architecture mapped in its autoload. I'm trying to build a high traffic website and I'm trying to minimize the overhead as much as possible before starting to make any hardware scaling. Do you have any idea how can I "force" laravel 4 into lazy loading the classes, as in ... whenever they are requested by the code for the given request.
The way I see it now, when it parses the routes it includes all controllers, makes a reflection class of all of them to parse the methods so that it has them mapped in the request memory. IMO that's quite the overkill. A simple Hello World costs me 5Mb ram and 15ms page generation time. That is too much for me. It's like the most hyped framework at the moment and its hyped as lightweight but 5mb/15ms is not lightweight in any case :/
There is a great argument/explanation here: http://forums.laravel.io/viewtopic.php?id=8175
Laravel 4 is meant to use more framework agnostic packages than Laravel 3.
Laravel 3 is very lightweight, perhaps you could look into using v3 instead. It's still actively being used and supported throughout the community.

Symfony 2 and Twig cache — are they the same?

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.

Categories