Skip to content

Instantly share code, notes, and snippets.

@jazeabby
Last active May 19, 2020 11:51
Show Gist options
  • Save jazeabby/bdf81d0deee1d3688ff40bed2845d867 to your computer and use it in GitHub Desktop.
Save jazeabby/bdf81d0deee1d3688ff40bed2845d867 to your computer and use it in GitHub Desktop.
Initial Usage of Cache Model in a controller
<?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