Zend_Cache注解

<?php

/**
 * Zend Framework
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://framework.zend.com/license/new-bsd
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@zend.com so we can send you a copy immediately.
 *
 * @category   Zend
 * @package    Zend_Cache
 * @copyright  Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 
*/


/**
 * @package    Zend_Cache
 * @copyright  Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 
*/
abstract class Zend_Cache
{

    
/**
     * Available frontends 可用的前端操作模块
     * Core
     * Output     缓存输出结果
     * Class    缓存 类
     * File        缓存文件
     * Function 缓存特定函数
     * Page        缓存页面
     * 
     * @var array $availableFrontends array of frontend name (string)
     
*/
    
public static $availableFrontends = array('Core', 'Output', 'Class', 'File', 'Function', 'Page');

    
/**
     * Available backends 可用的后端适配器
     *
     * File     保存缓存到文件
     * Sqlite    保存缓存到Sqlite数据库
     * Memcached 保存缓存内存
     * Apc
     * ZendPlatform
     * 
     * @var array $availableBackends array of backends name (string)
     
*/
    
public static $availableBackends = array('File', 'Sqlite', 'Memcached', 'Apc', 'ZendPlatform');

    
/**
     * Consts for clean() method    清除缓存所用到的 常量 
     
*/
    
const CLEANING_MODE_ALL              = 'all';            //清除所有缓存标记
    const CLEANING_MODE_OLD                 = 'old';        //清除过期
    const CLEANING_MODE_MATCHING_TAG     = 'matchingTag';    //清除指定标记
    const CLEANING_MODE_NOT_MATCHING_TAG = 'notMatchingTag';//清除不匹配的标记

    
/**
     * Factory  工厂方法
     *
     * @param string $frontend frontend name     前端 字符窜类型
     * @param string $backend backend name        后端
     * @param array $frontendOptions associative array of options for the corresponding frontend constructor 前端参数
     * @param array $backendOptions associative array of options for the corresponding backend constructor 后端参数
     
*/
    
public static function factory($frontend, $backend, $frontendOptions = array(), $backendOptions = array())
    {

        
// because lowercase will fail    此处转成 首字大写方式 主要是为匹配 $availableFrontends、$availableBackends 所定义的内容
        $frontend = self::_normalizeName($frontend);
        
$backend  = self::_normalizeName($backend);

        
if (!in_array($frontend, self::$availableFrontends)) {    //不存在的前端模块
            self::throwException("Incorrect frontend ($frontend)");
        }
        
if (!in_array($backend, Zend_Cache::$availableBackends)) {//不存在的后端模块
            self::throwException("Incorrect backend ($backend)");
        }

        
// For perfs reasons, with frontend == 'Core', we can interact with the Core itself
        //生成 要加载的前端模块类名 如果是 Core 则加载 Zend_Cache_Core 否则加载 Zend_Cache_Frontend_$frontend

        $frontendClass = 'Zend_Cache_' . ($frontend != 'Core' ? 'Frontend_' : ''. $frontend;

        
$backendClass = 'Zend_Cache_Backend_' . $backend;    //生成 要加载的后端模块类名

        // For perfs reasons, we do not use the Zend_Loader::loadClass() method 主要是为了减少耦合 依赖
        // (security controls are explicit) 转换成 具体的路径

        require_once str_replace('_', DIRECTORY_SEPARATOR, $frontendClass. '.php';
        
require_once str_replace('_', DIRECTORY_SEPARATOR, $backendClass. '.php';

        
$frontendObject = new $frontendClass($frontendOptions);
        
$backendObject = new $backendClass($backendOptions);
        
$frontendObject->setBackend($backendObject);    //利用前端模块的方法 保存所采用的后端模块实例
        return $frontendObject//返回生成的前端实例

    }

    
/**
     * Throw an exception
     *  异常类
     * Note : for perf reasons, the "load" of Zend/Cache/Exception is dynamic
     
*/
    
public static function throwException($msg)
    {
        
// For perfs reasons, we use this dynamic inclusion
        require_once 'Zend/Cache/Exception.php';
        
throw new Zend_Cache_Exception($msg);
    }

    
/**
     * Normalize frontend and backend names to allow multiple words TitleCased
     * 返回规范 后的字符窜 比如 首字大写 去除空格等..
     * @param  string $name
     * @return string
     
*/
    
protected static function _normalizeName($name)
    {
        
$name = ucfirst(strtolower($name));
        
$name = str_replace(array('-', '_', '.'), ' ', $name);
        
$name = ucwords($name);
        
$name = str_replace(' ', '', $name);
        
return $name;
    }

}
 
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值