⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 core.php

📁 一款可以和GOOGLE媲美的开源统计系统,运用AJAX.功能强大. 无色提示:按照需要PHP5.1以上和MySQL数据库支持。
💻 PHP
📖 第 1 页 / 共 2 页
字号:
     * @param boolean $doNotTestCacheValidity if set to true, the cache validity won't be tested     * @param boolean $doNotUnserialize do not serialize (even if automatic_serialization is true) => for internal use     * @return mixed cached datas (or false)     */    public function load($id, $doNotTestCacheValidity = false, $doNotUnserialize = false)    {        if (!$this->_options['caching']) {            return false;        }        $this->_lastId = $id;                self::_validateIdOrTag($id);        $data = $this->_backend->load($id, $doNotTestCacheValidity);        if ($data===false) {            // no cache available            return false;        }        if ((!$doNotUnserialize) && $this->_options['automatic_serialization']) {            // we need to unserialize before sending the result            return unserialize($data);        }        return $data;    }    /**     * THIS METHOD IS DEPRECATED : USE LOAD() INSTEAD (same syntax) !     *      * it will be removed in ZF 1.1 !     */    public function get($id, $doNotTestCacheValidity = false, $doNotUnserialize = false)    {        $this->_log("get() method is deprecated => use load() method instead (same syntax) !");        return $this->load($id, $doNotTestCacheValidity, $doNotUnserialize);    }    /**     * Test if a cache is available for the given id      *     * @param string $id cache id     * @return boolean true is a cache is available, false else     */    public function test($id)     {        if (!$this->_options['caching']) {            return false;        }        self::_validateIdOrTag($id);        $this->_lastId = $id;        return $this->_backend->test($id);    }    /**     * Save some data in a cache      *      * @param mixed $data data to put in cache (can be another type than string if automatic_serialization is on)     * @param cache $id cache id (if not set, the last cache id will be used)     * @param array $tags cache tags     * @param int $specificLifetime if != false, set a specific lifetime for this cache record (null => infinite lifetime)     * @return boolean true if no problem     */    public function save($data, $id = null, $tags = array(), $specificLifetime = false)     {        if (!$this->_options['caching']) {            return true;        }        if (is_null($id)) {            $id = $this->_lastId;        }        self::_validateIdOrTag($id);          self::_validateTagsArray($tags);           if ($this->_options['automatic_serialization']) {            // we need to serialize datas before storing them            $data = serialize($data);        } else {            if (!is_string($data)) {                Zend_Cache::throwException("Datas must be string or set automatic_serialization = true");            }        }        // automatic cleaning         if ($this->_options['automatic_cleaning_factor'] > 0) {            $rand = rand(1, $this->_options['automatic_cleaning_factor']);            if ($rand==1) {                $this->clean('old');            }        }        $result = $this->_backend->save($data, $id, $tags, $specificLifetime);        if (!$result) {            // maybe the cache is corrupted, so we remove it !            if ($this->_options['logging']) {                $this->_log("Zend_Cache_Core::save() : impossible to save cache (id=$id)");            }            $this->remove($id);            return false;        }        if ($this->_options['write_control']) {            $data2 = $this->_backend->load($id, true);            if ($data!=$data2) {                $this->_log('Zend_Cache_Core::save() / write_control : written and read data do not match');                $this->remove($id);                return false;            }        }        return true;    }    /**     * Remove a cache      *      * @param string $id cache id to remove     * @return boolean true if ok     */    public function remove($id)    {        if (!$this->_options['caching']) {            return true;        }        self::_validateIdOrTag($id);        return $this->_backend->remove($id);    }    /**     * Clean cache entries     *      * Available modes are :     * 'all' (default)  => remove all cache entries ($tags is not used)     * 'old'            => remove too old cache entries ($tags is not used)      * 'matchingTag'    => remove cache entries matching all given tags      *                     ($tags can be an array of strings or a single string)      * 'notMatchingTag' => remove cache entries not matching one of the given tags     *                     ($tags can be an array of strings or a single string)                                 *      * @param string $mode     * @param mixed $parameters       * @return boolean true if ok     */    public function clean($mode = 'all', $tags = array())    {        if (!$this->_options['caching']) {            return true;        }        if (!in_array($mode, array(Zend_Cache::CLEANING_MODE_ALL, Zend_Cache::CLEANING_MODE_OLD, Zend_Cache::CLEANING_MODE_MATCHING_TAG, Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG))) {            Zend_Cache::throwException('Invalid cleaning mode');        }        self::_validateTagsArray($tags);        return $this->_backend->clean($mode, $tags);    }    // ------------------------------------    // --- Private or protected methods ---    // ------------------------------------    /**     * Validate a cache id or a tag (security, reliable filenames, reserved prefixes...)     *      * Throw an exception if a problem is found     *      * @param string $string cache id or tag     */    private static function _validateIdOrTag($string)    {        if (!is_string($string)) {            Zend_Cache::throwException('Invalid id or tag : must be a string');        }        if (substr($string, 0, 9) == 'internal-') {            Zend_Cache::throwException('"internal-*" ids or tags are reserved');        }        if (!preg_match('~^[\w]+$~', $string)) {            Zend_Cache::throwException('Invalid id or tag : must use only [a-zA-Z0-9_]');        }    }    /**     * Validate a tags array (security, reliable filenames, reserved prefixes...)     *      * Throw an exception if a problem is found     *      * @param array $tags array of tags     */    private static function _validateTagsArray($tags)    {        if (!is_array($tags)) {            Zend_Cache::throwException('Invalid tags array : must be an array');        }        foreach($tags as $tag) {            self::_validateIdOrTag($tag);        }        reset($tags);    }    /**     * Make sure if we enable logging that the Zend_Log class     * is available.     * Create a default log object if none is set.     *     * @return void     * @throws Zend_Cache_Exception     */    protected function _loggerSanity()    {        if (!isset($this->_options['logging']) || !$this->_options['logging']) {            return;        }        try {            require_once 'Zend/Loader.php';            Zend_Loader::loadClass('Zend_Log');        } catch (Zend_Exception $e) {            Zend_Cache::throwException('Logging feature is enabled but the Zend_Log class is not available');        }        if (isset($this->_options['logger']) && $this->_options['logger'] instanceof Zend_Log) {            return;        }        // Create a default logger to the standard output stream        Zend_Loader::loadClass('Zend_Log_Writer_Stream');        $logger = new Zend_Log(new Zend_Log_Writer_Stream('php://output'));        $this->_options['logger'] = $logger;    }    /**     * Log a message at the WARN (4) priority.     *     * @param string $message     * @return void     * @throws Zend_Cache_Exception     */    protected function _log($message, $priority = 4)    {        if (!$this->_options['logging']) {            return;        }        if (!(isset($this->_options['logger']) || $this->_options['logger'] instanceof Zend_Log)) {            Zend_Cache::throwException('Logging is enabled but logger is not set');        }        $logger = $this->_options['logger'];        $logger->log($message, $priority);    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -