Location: PHPKode > projects > web.framework > web.framework-1.0.0/web.framework/AJAX/CacheDriver/WADefaultCache.class.php
<?php
/**
 * Project:     web.framework: the PHP5 MVC framework
 * File:		cache.WADefaultCache.class.php
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * You may contact the authors of web.framework by e-mail at:
 * hide@address.com
 *
 * The latest version of web.framework can be obtained from:
 * http://sourceforge.net/projects/webframework
 *
 * @link http://sourceforge.net/projects/webframework
 * @copyright 2005 Marcin Staniszczak
 * @author Marcin Staniszczak <hide@address.com>
 * @version 1.0.0
 */


/**
 * AJAX's default cache driver
 *
 * @name WADefaultCache
 * @version 1.0.0
 * @package web.framework
 * @subpackage web.AJAX
 *
 * @author Marcin Staniszczak
 * @copyright 2005 Marcin Staniszczak
 */
class WADefaultCache {
	/**
	 * @access private
	 * @var string
	 */
	private $strCachePath = '';

	/**
	 * The class constructor
	 *
	 * @access public
	 * @param string path to cache directory
	 */
	public function __construct($strCachePath) {
		$this->strCachePath = $strCachePath;
	}

	/**
	 * Load cache
	 *
	 * @access public
	 * @param string class's name
	 * @param integer class file's date
	 * @return false - cache don't exist or cache is older than class file, in otherwise cache content
	 */
	public function load($strClassName, $intDate) {
		if (!file_exists($this->strCachePath.$strClassName)) {
			return false;
		}

		if (filectime($this->strCachePath.$strClassName)<$intDate) {
			return false;
		}
//print_r(file($this->strCachePath.$strClassName));

		return implode("", file($this->strCachePath.$strClassName));
	}

	/**
	 * Save cache
	 *
	 * @access public
	 * @param string class's name
	 * @param string JS content
	 * @throws WF_AJAX_Exception
	 */
	public function save($strClassName, $strContent) {
		$resFile = fopen($this->strCachePath.$strClassName, 'w');

		if ($resFile!==false) {
			fwrite($resFile, $strContent);
			fclose($resFile);
		} else {
			throw new WF_AJAX_Exception(sprintf(Languages::$MESSAGES[WebFramework::$strLanguage]['EXCEPTIONS']['AJAX']['CACHE_SAVE'], $this->strCachePath.$strClassName));
		}
	}
}

/**
 * Exception of AJAX
 * @subpackage exceptions
 */
class WF_AJAXException extends Exception {}
?>
Return current item: web.framework