SoFunction
Updated on 2025-03-10

Yii CFileCache Analysis of the reasons why the value cannot be obtained

I configured it in the configuration file

‘cache'=>array(
‘class'=>'',
),

Set in the controller

return array(
array(
‘COutputCache+pro',
‘duration'=>86400,
‘varyByParam'=>array(‘id'),
),

Then the database is turned on‘schemaCachingDuration'=>3600,

There are cached files for the first time and I found that it has indeed accelerated the access speed.

But after a long time period, maybe 10 minutes later, I found that the cache file below runtime/cache suddenly disappeared

I don't know what the reason is. I've been following it for a long time before I discovered this problem

In addition, I also found that there are folders in the cache directory: 0a d6 63 3a named. I don’t know what this is.

Why is the cached files suddenly lost online?

The cache file is on disk D, and the data space is very large

1. Yii's buffer needs to be configured inside.

/****************/
‘cache' => array (
‘class' => ‘'
)

After the configuration is completed, just need to be in the controller...

Yii::app ()->cache->set($key,$value,$expire);
Yii::app ()->cache->get($key);

2. Configure multiple caches

Configuration

‘cache' => array (
‘class' => ‘'
),
‘dbcache' => array (
‘class' => ‘'
)

The controller only needs to be called with the corresponding cacheid

like:Yii::app ()->dbcache

3. Page buffering means statically making the entire page

The configuration is still the same

Controller: You can use the COutputCache class as a behavior filter in our controller class.

public function filters() {
return array (
array (
‘COutputCache',
‘duration' => 600,
‘ varyByParam' => array(‘id')
)
);
}

COutputCache is used as a strategy to automatically generate key names when cached data. Here is a list of available:

varyByRoute: By setting this option to true, the routing part of the specific request will be used as part of the independent identifier to generate cached data. So, you can use a combination of request controller and acion to distinguish cached content.

varyBySession: By setting this option to true, a unique session id will be used to distinguish the content in the cache. Each user's session is different, but can be used to serve caches.

varyByParam: As mentioned earlier, here is to distinguish cached content by using the parameters in the input GET.

varyByExpression: Set a PHP expression for this option. We can use the results of the corresponding expression to distinguish the cached content.

Also note that the default cacheid of COutputCache is cache

4. Fragment cache

Fragment cache is used to cache part of a page. We can use fragment cache in view scripts. We do this by using the CController::beginCache() and CController::endCache() methods.

…some HTML content…
<?php if($this—>beginCache($key))?>
…content to be cached…
<?php $this—>endCache(); ?>
…other HTML content…

The above is an analysis of the reasons why Yii CFileCache cannot get the value introduced by the editor. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to everyone in time. Thank you very much for your support for my website!