Hi, How to implement configurable frontend HTML cache (the whole html of the action)??

Details

  • Phalcon version: 3.0.1
  • PHP Version:7.0.6
  • Operating System:centos6.7
  • Server: Nginx

This is my expected results:

the global cache config(config/htmlcacherule.php):

<?php

return [

     'HTML_CACHE_ON' => 'on', //on is use html cache; off is shutup

     'HTML_CACHE_RULES' =>[

                'Index:index'      => ['this is server url will be md5', 'this is cache time'],

                'Search:index'    => ['this is server url will be md5', 'this is cache time'],

                'Article:'                => ['this is server url will be md5', 'this is cache time'],

     ],

];

?>

Then the cacheDir will be written html cache file by the map of the action. If I access the action Index:index and in the map of cache time, then return the html cache file, if expires, will access the action Index:index and rewrite the html cache file.

PS: 'Article:' will generate html cache file all his action.

#

I think it many days, but I do not how to implement it. Can any one help me??



64.5k

I followed how its done in the public website. https://github.com/phalcon/website/blob/master/app/app/controllers/ControllerBase.php#L105

if env === live

volt compileLaways false

and in every action ( or how its done there using beforeExecuteRoute) you check if cache exists if it doesnt you do $this->view->setVar()..

to understand it I think you need ~ 2 hours. This is phalcon's way, i am not sure which way exacly you were going for ...

maybe jurigag can help you with yours

edited Oct '16

hi , @lzo: I write a function like https://github.com/phalcon/website/blob/master/app/app/controllers/ControllerBase.php#L105 , but can't return html cache content which is set cache.

See my function https://github.com/phalcon/website/blob/master/app/app/controllers/ControllerBase.php#L105, can you tell me where is wrong that the html cache is real-time ??

you can test the url : http://localhost/index/index/ok/55555/nook/3333333?ok=233333



64.5k

if you use volt you dont have to return anythign. Volt is cached for himself the only think is that in the controllers you dont have to run queries/set variables

I use .phtml as template, not .volt.

Thanks for your answers.