I use file caching to cache the page output. Sometimes all the cache files are ok. Sometimes a few cache files are zero byte. These empty cache files are random (not consistently the same files).
I am using PHP 5.5.30 and Phalcon 2.0.9. The program is in development environment and I am the only user accessing the pages.
I cannot find similar problem in this forum or the internet so I think maybe I code my program wrongly. Thanks in advance for any suggestion.
Below are codes that I used to set up $di and the controller. The generated cache ID is a camel-cased file name without any folder name.
$di->set('viewCache', function() use ($config){
//Cache data for one day by default
$frontCache = new Phalcon\Cache\Frontend\Output(array(
"lifetime" => 2592000
));
//File backend settings
$cache = new Phalcon\Cache\Backend\File($frontCache, array(
"cacheDir" => $config->application->cacheDir,
//"prefix" => "php"
));
return $cache;
});
/**
* Setting up the view component
*/
$di->setShared('view', function () use ($config) {
$view = new View();
$view->setViewsDir($config->application->viewsDir);
$view->registerEngines(array(
'.volt' => function ($view, $di) use ($config) {
$folder = $config->application->cacheDir.'compile/';
if ( ! @file_exists($folder))
{
@mkdir($folder, 0777, TRUE);
}
$volt = new VoltEngine($view, $di);
$volt->setOptions(array(
//'compiledPath' => $config->application->cacheDir,
'compiledPath' => $folder,
'compiledSeparator' => '_'
));
return $volt;
},
'.phtml' => 'Phalcon\Mvc\View\Engine\Php'
));
return $view;
});
use Phalcon\Mvc\Controller;
use Phalcon\Mvc\View;
class FunController extends Controller
{
public function indexAction()
{
$pageCacheID = $this->generatePageCacheID();
if(!($this->view->getCache()->exists($pageCacheID))) {
//generate content
}
//Save page to cache
$this->view->cache(array('key' => $pageCacheID, 'lifetime' => 86400));
}
}