Ticket #617: pluginCache.3.diff

File pluginCache.3.diff, 6.8 kB (added by hadrien, 5 months ago)

Avec les dernières modifications de nuks`

  • build/manifests/jelix-lib.mn

    old new  
    723723! WSDLException.class.php 
    724724! WSDLStruct.class.php 
    725725! WSException.class.php 
     726 
     727cd lib/jelix/cache/ 
     728  jCache.class.php 
     729 
     730cd lib/jelix/plugins/coord 
     731  cache 
     732 
     733cd lib/jelix/plugins/coord/cache 
     734  plugin.xml 
     735  cache.coord.php 
     736  cache.coord.ini.php.dist 
     737  lib/jelix/init.php 
  • lib/jelix/plugins/coord/cache/plugin.xml

    old new  
     1<?xml version="1.0" encoding="UTF-8"?> 
     2<plugin name="cache"> 
     3        <version major="1" minor="1" status="" copixversion=""  date="2008-06-11" /> 
     4        <author name="Hadrien Lanneau" email="contact@hadrien.eu" website="http://www.hadrien.eu" role="creator" /> 
     5        <description> 
     6                File cache 
     7        </description> 
     8</plugin> 
  • lib/jelix/plugins/coord/cache/cache.coord.php

    old new  
     1<?php 
     2/** 
     3* @package    jelix 
     4* @subpackage coord_plugin 
     5* @author     Hadrien Lanneau (contact at hadrien dot eu) 
     6* @copyright  2001-2005 CopixTeam, 2005-2007 Laurent Jouanneau, 2007 Frédéric Guillot, 2007 Antoine Detante 
     7* @copyright  2008 Hadrien.eu 
     8* 
     9* This class was get originally from an experimental branch of the Copix project 
     10* (PluginAuth, Copix 2.3dev20050901, http://www.copix.org) 
     11* Few lines of code are still copyrighted 2001-2005 CopixTeam (LGPL licence). 
     12* Initial authors of this Copix classes are Gerald Croes and Laurent Jouanneau, 
     13* and this class was adapted for Jelix by Laurent Jouanneau 
     14* 
     15* @licence  http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public Licence, see LICENCE file 
     16*/ 
     17 
     18require( 
     19        JELIX_LIB_PATH . 'cache/jCache.class.php' 
     20); 
     21 
     22class CacheCoordPlugin implements jICoordPlugin 
     23{ 
     24        /** 
     25         * Activate cache 
     26         * 
     27         * @var boolean 
     28         **/ 
     29        public $activated = false; 
     30        /** 
     31         * time expiration (in milliseconds) 
     32         * 
     33         * @var Integer 
     34         **/ 
     35        private $_expires; 
     36         
     37        /** 
     38         * Cache filename 
     39         * 
     40         * @var string 
     41         **/ 
     42        private $_fileKey; 
     43         
     44        /** 
     45         * Cache folder path 
     46         * 
     47         * @var string 
     48         **/ 
     49        public $path; 
     50         
     51        /** 
     52         * path into cache folder 
     53         * 
     54         * @var string 
     55         **/ 
     56        private $_localPath; 
     57         
     58         
     59        public function __construct($config) 
     60        { 
     61                if (isset($config['cache']) and 
     62                        $config['cache'] == 1) 
     63                { 
     64                        $this->activated = true; 
     65                         
     66                        if (isset($config['path'])) 
     67                        { 
     68                                $this->path = JELIX_APP_TEMP_PATH . 
     69                                        $config['path'] . 
     70                                        DIRECTORY_SEPARATOR; 
     71                        } 
     72                        else 
     73                        { 
     74                                $this->path = JELIX_APP_TEMP_PATH . 'cache/'; 
     75                        } 
     76                } 
     77        } 
     78         
     79        /** 
     80         * Get request params and check file cached 
     81         * @param {array} $params Params array 
     82         * @return void 
     83         **/ 
     84        public function beforeAction($params) 
     85        { 
     86                // Check if cache is activated and if this request ask for cache 
     87                if ($this->activated and 
     88                        isset($params['cache.expires'])) 
     89                { 
     90                        global $gJCoord; 
     91                        // create a path from module/action 
     92                        $this->_localPath .=  
     93                                $gJCoord->moduleName . '/' . 
     94                                str_replace( 
     95                                        ':', 
     96                                        '_', 
     97                                        $gJCoord->actionName 
     98                                ) . '/'; 
     99                         
     100                        jFile::createDir( 
     101                                $this->path . 
     102                                $this->_localPath 
     103                        ); 
     104                         
     105                        // get md5 key from get params 
     106                        $this->_fileKey = md5( 
     107                                serialize( 
     108                                        $gJCoord->request->params 
     109                                ) 
     110                        ); 
     111                         
     112                        // Test file time 
     113                        $this->_expires = $params['cache.expires']; 
     114                        if (@filemtime( 
     115                                        $this->path . 
     116                                        $this->_localPath . 
     117                                        $this->_fileKey 
     118                                ) < time() - $this->_expires) 
     119                        { 
     120                                // Start cache 
     121                                ob_start(); 
     122                        } 
     123                        else 
     124                        { 
     125                                // Include cached file 
     126                                include( 
     127                                        $this->path . 
     128                                        $this->_localPath . 
     129                                        $this->_fileKey 
     130                                ); 
     131                                exit(); 
     132                        } 
     133                } 
     134        } 
     135        public function beforeOutput() 
     136        { 
     137                 
     138        } 
     139        public function afterProcess() 
     140        { 
     141                if ($this->activated and 
     142                        $this->_expires) 
     143                { 
     144                        // end cache 
     145                        $cache = ob_get_contents(); 
     146                        ob_end_flush(); 
     147                         
     148                        // Write in file 
     149                        jFile::write( 
     150                                $this->path . 
     151                                        $this->_localPath . 
     152                                        $this->_fileKey, 
     153                                $cache 
     154                        ); 
     155                } 
     156        } 
     157} 
  • lib/jelix/plugins/coord/cache/cache.coord.ini.php.dist

    old new  
     1;<?php die(''); ?> 
     2;for security reasons , don't remove or modify the first line 
     3 
     4;============= Main parameters 
     5 
     6; Activate cache (deactivate on dev mode) 
     7cache = on 
     8 
     9; Path parameter from app temp folder  
     10;path = "cache" 
  • lib/jelix/init.php

    old new  
    125125$gLibPath=array('Db'=>JELIX_LIB_PATH.'db/', 'Dao'=>JELIX_LIB_PATH.'dao/', 
    126126 'Forms'=>JELIX_LIB_PATH.'forms/', 'Event'=>JELIX_LIB_PATH.'events/', 
    127127 'Tpl'=>JELIX_LIB_PATH.'tpl/', 'Acl'=>JELIX_LIB_PATH.'acl/', 'Controller'=>JELIX_LIB_PATH.'controllers/', 
    128  'Auth'=>JELIX_LIB_PATH.'auth/', 'Installer'=>JELIX_LIB_PATH.'installer/'); 
     128 'Auth'=>JELIX_LIB_PATH.'auth/', 'Installer'=>JELIX_LIB_PATH.'installer/', 
     129'jCache'=>JELIX_LIB_PATH.'cache/'); 
    129130 
    130131/** 
    131132 * __autoload function used by php to try to load an unknown class 
    132133 */ 
    133134function __autoload($class){ 
    134     if(preg_match('/^j(Dao|Tpl|Acl|Event|Db|Controller|Forms|Auth|Installer).*/i', $class, $m)){ 
     135    if(preg_match('/^j(Dao|Tpl|Acl|Event|Db|Controller|Forms|Auth|Installer|jCache).*/i', $class, $m)){ 
    135136        $f=$GLOBALS['gLibPath'][$m[1]].$class.'.class.php'; 
    136137    }elseif(preg_match('/^cDao(?:Record)?_(.+)_Jx_(.+)_Jx_(.+)$/', $class, $m)){ 
    137138        // pour les dao stockés en sessions notament 
  • lib/jelix/cache/jCache.class.php

    old new  
     1<?php 
     2/** 
     3* jCache : interact with cache plugin 
     4*/ 
     5class jCache 
     6{ 
     7        /** 
     8         * Clean cache for a particular selector 
     9         * 
     10         * @param {string} $actSel Page selector to clean 
     11         * @return Boolean 
     12         * @author Hadrien 
     13         **/ 
     14        static function clean($actSel) 
     15        { 
     16                global $gJCoord; 
     17                 
     18                if (!isset($gJCoord->plugins['cache'])) 
     19                { 
     20                        return false; 
     21                } 
     22                 
     23                $sel = new jSelectorAct( 
     24                        $actSel, 
     25                        true 
     26                ); 
     27                 
     28                jFile::removeDir( 
     29                        $gJCoord->plugins['cache']->path . 
     30                        $sel->module . '/' . 
     31                                $sel->controller . '_' . 
     32                                $sel->method 
     33                ); 
     34                 
     35                return true; 
     36        } 
     37} 
Download in other formats: Original Format