PageRenderTime 28ms CodeModel.GetById 19ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/framework/vendor/smarty3/lib/libs/sysplugins/smarty_internal_cache.php

http://zoop.googlecode.com/
PHP | 102 lines | 37 code | 9 blank | 56 comment | 6 complexity | a88bb0f2fbacd6b0d9c0548893b3e5ac MD5 | raw file
  1<?php
  2
  3/**
  4* Project:     Smarty: the PHP compiling template engine
  5* File:        smarty_internal_cache.php
  6* SVN:         $Id: $
  7* 
  8* This library is free software; you can redistribute it and/or
  9* modify it under the terms of the GNU Lesser General Public
 10* License as published by the Free Software Foundation; either
 11* version 2.1 of the License, or (at your option) any later version.
 12* 
 13* This library is distributed in the hope that it will be useful,
 14* but WITHOUT ANY WARRANTY; without even the implied warranty of
 15* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 16* Lesser General Public License for more details.
 17* 
 18* You should have received a copy of the GNU Lesser General Public
 19* License along with this library; if not, write to the Free Software
 20* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 21* 
 22* For questions, help, comments, discussion, etc., please join the
 23* Smarty mailing list. Send a blank e-mail to
 24* smarty-discussion-subscribe@googlegroups.com
 25* 
 26* @link http://www.smarty.net/
 27* @copyright 2008 New Digital Group, Inc.
 28* @author Monte Ohrt <monte at ohrt dot com> 
 29* @author Uwe Tews 
 30* @package Smarty
 31* @subpackage PluginsInternal
 32* @version 3-SVN$Rev: 3286 $
 33*/
 34
 35class Smarty_Internal_Cache {
 36  
 37    protected $smarty;
 38
 39    function __construct($smarty) {
 40      $this->smarty = $smarty;
 41    }
 42
 43    /**
 44    * Loads cache resource.
 45    * 
 46    * @return object of cache resource
 47    */
 48    public function loadResource($type = null) {
 49        if (!isset($type)) {
 50            $type = $this->smarty->caching_type;
 51        } 
 52        // already loaded?
 53        if (isset($this->smarty->cache_resource_objects[$type])) {
 54            return $this->smarty->cache_resource_objects[$type];
 55        } 
 56        if (in_array($type, $this->smarty->cache_resource_types)) {
 57            $cache_resource_class = 'Smarty_Internal_CacheResource_' . ucfirst($type);
 58            return $this->smarty->cache_resource_objects[$type] = new $cache_resource_class($this->smarty);
 59        } 
 60        else {
 61            // try plugins dir
 62            $cache_resource_class = 'Smarty_CacheResource_' . ucfirst($type);
 63            if ($this->smarty->loadPlugin($cache_resource_class)) {
 64                return $this->smarty->cache_resource_objects[$type] = new $cache_resource_class($this->smarty);
 65            } 
 66            else {
 67                throw new Exception("Unable to load cache resource '{$type}'");
 68            } 
 69        } 
 70    } 
 71
 72    /**
 73    * Empty cache folder
 74    * 
 75    * @param integer $exp_time expiration time
 76    * @param string $type resource type
 77    * @return integer number of cache files deleted
 78    */
 79    function clearAll($exp_time = null, $type = null)
 80    { 
 81        return $this->loadResource($type)->clearAll($exp_time);
 82    }        
 83
 84    /**
 85    * Empty cache for a specific template
 86    * 
 87    * @param string $template_name template name
 88    * @param string $cache_id cache id
 89    * @param string $compile_id compile id
 90    * @param integer $exp_time expiration time
 91    * @param string $type resource type
 92    * @return integer number of cache files deleted
 93    */
 94    function clear($template_name, $cache_id = null, $compile_id = null, $exp_time = null, $type = null)
 95    { 
 96       // load cache resource
 97        $cacheResource = $this->loadResource($type);
 98    
 99        return $cacheResource->clear($template_name, $cache_id, $compile_id, $exp_time);
100    }
101    
102}