Source for file Frontend.php
Documentation is available at Frontend.php
declare(encoding = "utf-8");
* This file is part of ForwardFW a web application framework.
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU 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
* General Public License for more details.
* You should have received a copy of the GNU 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
* @author Alexander Opitz <opitz.alexander@primacom.net>
* @copyright 2009-2010 The Authors
* @license http://www.gnu.org/copyleft/gpl.html GNU General Public License
* @link http://forwardfw.sourceforge.net
* @since File available since Release 0.0.8
require_once 'ForwardFW/Config/Cache/Data.php';
require_once 'ForwardFW/Config/Cache/Frontend.php';
require_once 'ForwardFW/Interface/Application.php';
require_once 'ForwardFW/Interface/Cache/Backend.php';
require_once 'ForwardFW/Interface/Cache/Frontend.php';
require_once 'ForwardFW/Cache/Exception/TimeOut.php';
require_once 'ForwardFW/Cache/Exception/NoData.php';
require_once 'ForwardFW/Cache/Exception/IsGenerating.php';
* @author Alexander Opitz <opitz.alexander@primacom.net>
* @license http://www.gnu.org/copyleft/gpl.html GNU General Public License
* @link http://forwardfw.sourceforge.net
* @param ForwardFW_Interface_Application $application The running application
* @param ForwardFW_Interface_Cache_Backend $backend Backend instance.
ForwardFW_Interface_Application $application,
ForwardFW_Interface_Cache_Backend $backend
$this->application = $application;
$this->backend = $backend;
* Builds an instance of cache
* @param ForwardFW_Interface_Application $application The running application
* @param ForwardFW_Config_Cache_Frontend $config Configuration of caching
* @return ForwardFW_Interface_Cache_Frontend The cache Frontend
ForwardFW_Interface_Application $application,
ForwardFW_Config_Cache_Frontend $config
$backend = self::getBackend(
$config->getCacheBackend(),
$config->getBackendConfig()
$frontend = self::getFrontend($application, $config, $backend);
* Builds Backend of a cache configuration
* @param ForwardFW_Interface_Application $application The running application
* @param string $strCacheBackend Configuration of caching
* @param ForwardFW_Config_Cache_Backend $config Configuration of caching
* @return ForwardFW_Interface_Cache_Backend Caching Backend.
ForwardFW_Interface_Application $application,
ForwardFW_Config_Cache_Backend $config
if (isset ($GLOBALS['Cache']['backend'][$strCacheBackend])) {
$return = $GLOBALS['Cache']['backend'][$strCacheBackend];
include_once str_replace('_', '/', $strCacheBackend) . '.php';
$return = new $strCacheBackend($application, $config);
$GLOBALS['Cache']['backend'][$strCacheBackend] = $return;
* Builds Backend of a cache configuration
* @param ForwardFW_Interface_Application $application The running application
* @param ForwardFW_Config_Cache_Frontend $config Configuration of caching
* @param ForwardFW_Interface_Cache_Backend $backend Backend for the frontend
* @return ForwardFW_Interface_Cache_Frontend Caching Frontend.
ForwardFW_Interface_Application $application,
ForwardFW_Config_Cache_Frontend $config,
ForwardFW_Interface_Cache_Backend $backend
$class = $config->getCacheFrontend();
if (isset ($GLOBALS['Cache']['frontend'][$class])) {
$return = $GLOBALS['Cache']['frontend'][$class];
$return = new $class($application, $backend);
$GLOBALS['Cache']['frontend'][$class] = $return;
* Returns content from cache or gathers the data
* @param ForwardFW_Config_Cache_Data $config What data should be get from cache
* @return mixed The data you requested.
public function getCache(ForwardFW_Config_Cache_Data $config)
switch ($config->getTimeout()) {
$nTime = time() - $config->getTimeout();
$mData = $this->backend->getData($strHash, $nTime);
* Returns the real data and add it to cache. If real data fails tries to
* get old data from cache if available.
* @param String $strHash Hash of cache
* @param ForwardFW_Config_Cache_Data $config What data should be get
* @param boolean $bOldAvailable True if backend has old
* @return mixed The data you requested.
ForwardFW_Config_Cache_Data $config,
$this->backend->setData($strHash, $mData);
if ($config->getReserveOld() && $bOldAvailable) {
$mData = $this->backend->getData($strHash, 0);
abstract protected function calculateHash(ForwardFW_Config_Cache_Data $config);
abstract protected function getDataToCache(ForwardFW_Config_Cache_Data $config);
* Calculates a hash by serialize and md5.
* @param mixed $mValue The data from which the hash should be gathered.
* @return string The hash.
|