S
S
Sergey2014-12-05 11:44:35
Yii
Sergey, 2014-12-05 11:44:35

How to know if a request is cached in Yii 1 (memcached)?

I connected memcache in the config, everything is configured and enabled on the machine (dll and the service itself is running)
How can I find out if requests are really cached?
Climbed into the framework, found such a thing CDbCommand 495 line

if(($result=$cache->get($cacheKey))!==false)
      {                         
        Yii::trace('Query result found in cache','system.db.CDbCommand');
        return $result[0];
      }

The result is always in the false condition, i.e. the program never enters it. Do I understand correctly that caching does not work?
Here's the query I'm testing on:
$result = Yii::app()->db->cache(600)->createCommand('SELECT COUNT(*) as count FROM wo_users')->queryRow();

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Vapelnik, 2014-12-11
@dvapelnik

you can check memcached statistics from the command line. here is a link .
1. Clear the cache.
2. See if the cache is empty - the cache must be empty
3. We cache ONLY one request.
4. Make this request
5. Check if the cache is empty - the cache must not be empty
The condition is set to check if there is data in the cache for such and such a key. If they are, then the data is taken from the cache. If they are not there, then you need to put them there and return the data. Before using the cache, you need to describe it as a module in the config. To check if the cache itself works, you can check it directly without caching requests, but by caching just data:

$dataCacheKey = 'data_key';
if($data = Yii::app()->cache->get($dataCacheKey)){
    echo 'Data cached';
}else{
    $data = 'asd';
    Yii::app()->cache->add($dataCacheKey, $data);
}

return $data;
// навскидку как-то так

you can use CDummyCache to write code for caching functions, but there is no caching. Such a cache-dummy, which type and caches, but it does not cache anything, but provides a full interface for caching. Then in the config, you can simply change the class that will cache this whole thing and you won’t need to change anything in the code. Read the man page on caching in Yii

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question