Last active
May 19, 2020 11:51
-
-
Save jazeabby/bdf81d0deee1d3688ff40bed2845d867 to your computer and use it in GitHub Desktop.
Initial Usage of Cache Model in a controller
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App/Controllers; | |
use App/models/CacheModel as Cache; | |
Class HomeController | |
{ | |
private $cache; | |
public function __construct() | |
{ | |
$this->cache = new Cache(); | |
} | |
public function index() | |
{ | |
$key_name = __CLASS__.'_'.__METHOD__; | |
$html = $this->cache->get($key_name); | |
if (! empty($html)) { | |
echo $html; | |
exit(); | |
} | |
// data processing | |
// .. | |
// some more processing | |
// .. | |
// some more.. | |
// rendering the html view after data processing | |
$html = '<h1>My HTML Template/Page to output</H1>'; | |
$seconds_in_day = 60 * 60 * 24; | |
$this->cache->set($key_name, $html, $seconds_in_day); | |
echo $html; | |
exit(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment