summaryrefslogtreecommitdiff
path: root/lib/Minz/Cache.php
diff options
context:
space:
mode:
authorGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2014-06-13 18:51:52 +0200
committerGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2014-06-13 18:51:52 +0200
commitf58fdfe93dbf969338fe9cecbd728e0f7add4617 (patch)
treee1629da3361235d1c4ef28944624326491628045 /lib/Minz/Cache.php
parentc053825ff8f9792e692c101585481129b006937b (diff)
parent61f4d5457818204eb28ed394d4f1b97160542baa (diff)
Merge branch 'dev' into beta
Diffstat (limited to 'lib/Minz/Cache.php')
-rw-r--r--lib/Minz/Cache.php116
1 files changed, 0 insertions, 116 deletions
diff --git a/lib/Minz/Cache.php b/lib/Minz/Cache.php
deleted file mode 100644
index fcb627eb2..000000000
--- a/lib/Minz/Cache.php
+++ /dev/null
@@ -1,116 +0,0 @@
-<?php
-/**
- * MINZ - Copyright 2011 Marien Fressinaud
- * Sous licence AGPL3 <http://www.gnu.org/licenses/>
-*/
-
-/**
- * La classe Cache permet de gérer facilement les pages en cache
- */
-class Minz_Cache {
- /**
- * $expire timestamp auquel expire le cache de $url
- */
- private $expire = 0;
-
- /**
- * $file est le nom du fichier de cache
- */
- private $file = '';
-
- /**
- * $enabled permet de déterminer si le cache est activé
- */
- private static $enabled = true;
-
- /**
- * Constructeur
- */
- public function __construct () {
- $this->_fileName ();
- $this->_expire ();
- }
-
- /**
- * Setteurs
- */
- public function _fileName () {
- $file = md5 (Minz_Request::getURI ());
-
- $this->file = CACHE_PATH . '/'.$file;
- }
-
- public function _expire () {
- if ($this->exist ()) {
- $this->expire = filemtime ($this->file)
- + Minz_Configuration::delayCache ();
- }
- }
-
- /**
- * Permet de savoir si le cache est activé
- * @return true si activé, false sinon
- */
- public static function isEnabled () {
- return Minz_Configuration::cacheEnabled () && self::$enabled;
- }
-
- /**
- * Active / désactive le cache
- */
- public static function switchOn () {
- self::$enabled = true;
- }
- public static function switchOff () {
- self::$enabled = false;
- }
-
- /**
- * Détermine si le cache de $url a expiré ou non
- * @return true si il a expiré, false sinon
- */
- public function expired () {
- return time () > $this->expire;
- }
-
- /**
- * Affiche le contenu du cache
- * @print le code html du cache
- */
- public function render () {
- if ($this->exist ()) {
- include ($this->file);
- }
- }
-
- /**
- * Enregistre $html en cache
- * @param $html le html à mettre en cache
- */
- public function cache ($html) {
- file_put_contents ($this->file, $html);
- }
-
- /**
- * Permet de savoir si le cache existe
- * @return true si il existe, false sinon
- */
- public function exist () {
- return file_exists ($this->file);
- }
-
- /**
- * Nettoie le cache en supprimant tous les fichiers
- */
- public static function clean () {
- $files = opendir (CACHE_PATH);
-
- while ($fic = readdir ($files)) {
- if ($fic != '.' && $fic != '..') {
- unlink (CACHE_PATH.'/'.$fic);
- }
- }
-
- closedir ($files);
- }
-}