N
N
NatanNovak2014-01-03 13:27:31
Yii
NatanNovak, 2014-01-03 13:27:31

How to use Yii caching to implement caching of the database and template files into RAM?

Hello, friends ! Help to deal with caching in RAM.
We are developing a corp. portal in Yii 1.1 . There is Redis and a lot of RAM. I want speed.
I re-read a lot of articles and theories ... pairs, keys, etc. but did not understand how the caching of files (layouts, views) is practically implemented in the op. memory. No one to advise.
Please explain how I can use Yii to implement caching of the framework and template files into RAM, so that the portal would fly like a meteor for users, so that Durov and his VKontakte would be envious.
The question is only about Redis or Memcahed (at least). The practical principle, implementation experience and code are interesting.
Thanks in advance for the replies!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Chaika, 2014-01-03
@NatanNovak

I didn’t dig the topic, but the easiest way is to override the render method (by default in protected/components/Controller.php, if it doesn’t exist, then you need to create and inherit from CController).
In this method, we do something from the category:

public function render($view, $data = null, $return = false)
{
    $cache_key = $view . json_encode($data);
    $cached_data = Yii::app()->cache->get($cache_key);

    if (!$cached_data) {
        $cached_data = parent::render($view, $data, true);
        Yii::app()->cache->set($cache_key, $cached_data);
    }

    if ($return) {
        return $cached_data;
    } else {
        echo $cached_data;
    }
}

P
Pavel Volintsev, 2014-08-23
@copist

Look at the following sections in the documentation:
* page caching - about the fact that the entire content of the page can be cached
* fragment caching - about the fact that you can put a piece of HTML in the cache
* dynamic content caching - about the fact that you can include code inside the cached fragment , which changes (for example, in the cache of the entire page - a block of banners, every time the page is updated, show a different banner)
Contact if you need details ( https://toster.ru/user/copist)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question