Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Cache{
- private $folder = 'cache';
- private $timeout = 3600; //1hora
- private $name;
- public function __construct($file, $timeout){
- $this->name = $file;
- $this->timeout = $timeout;
- if($this->check()){
- $this->createCache();
- }
- }
- public function getPathFileName(){
- return sprintf('%s/%s', $this->folder, md5($this->name));
- }
- public function check(){
- $file = $this->getPathFileName();
- if(file_exists($file) && ( fileatime ( $file ) + $this->timeout) > time()) {
- return true;
- }else{
- return false;
- }
- }
- public function createCache(){
- ob_start();
- include_once($this->name);
- file_put_contents($this->getPathFileName(), ob_get_clean());
- }
- public function getContent(){
- return file_get_contents($this->getPathFileName());
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement