1. XenForo 1.5.14 中文版——支持中文搜索!现已发布!查看详情
  2. Xenforo 爱好者讨论群:215909318 XenForo专区

交流 【官网帮助】Defining a Cache

本帖由 woi9112015-05-09 发布。版面名称:XenForo中文版

  1. woi911

    woi911 VIP会员

    注册:
    2014-02-19
    帖子:
    283
    赞:
    59
    原帖:https://xenforo.com/help/cache/

    For large XenForo installations, it can be advantageous to define a cache in order to save on processing time and database queries.

    XenForo has the ability to store and retrieve various data from a cache, which can be configured in your library/config.php file.

    Example Cache Types
    The XenForo cache is an implementation of the Zend_Cache_Core front-end, and an extension of Zend_Cache_Backend for the back-end.

    Cache Front-End
    Configuring the front-end is easy, and involves simply adding the following lines to your library/config.php file:

    PHP:
    $config['cache']['enabled'] = true;
    $config['cache']['frontend'] = 'Core';
    $config['cache']['frontendOptions']['cache_id_prefix'] = 'xf_';
    You may alter the 'cache_id_prefix' values to suit your own needs. Advanced users may change other Zend_Cache_Core front-end options to fit their needs.

    If you wish to read and write XenForo sessions to the cache, add the following line to your library/config.php file:

    PHP:
    $config['cache']['cacheSessions'] = true;
    Note that your cache must have enough space to hold the sessions, or users may not be able to login properly. We do not recommend writing sessions to the cache if you are using APC as your cache back-end.

    The following are a few examples of cache back-ends that are usable by XenForo:

    File Back-End
    The simplest kind of cache back-end is a simple file store, which stores cache data as files in the temporary directory of your server.

    Configuration is equally simple:

    PHP:
    $config['cache']['backend'] = 'File';
    Full list of file cache options.
    http://framework.zend.com/manual/1.11/en/zend.cache.backends.html#zend.cache.backends.file


    APC Back-End
    If you have APC (Alternative PHP Cache) installed on your server, you may use it to store cache data.

    Note that some versions of APC may be susceptible to cache-slam issues, so if you do enable APC caching of data (in addition to the PHP opcode cache that it maintains automatically without requiring any configuration), you should monitor your server carefully for a time to ensure that it is running smoothly.

    PHP:
    $config['cache']['backend'] = 'Apc';
    Full list of APC cache options.
    http://framework.zend.com/manual/1.11/en/zend.cache.backends.html#zend.cache.backends.apc

    Memcached Back-End
    Memcached is an advanced storage mechanism for shared data, and can be used as a back-end for XenForo caching.

    It requires slightly more configuration than some simpler back-ends, for example:

    PHP:
    $config['cache']['backend'] = 'Memcached';
    $config['cache']['backendOptions'] = array(
        
    'compression' => false,
        
    'servers' => array(
            array(
                
    // your memcached server IP /address
                
    'host' => 'localhost',
               
                
    // memcached port
                
    'port' => 11211,
            )
        )
    );
    Full list of memcached cache options.

    http://framework.zend.com/manual/1.11/en/zend.cache.backends.html#zend.cache.backends.memcached
     
  2. woi911

    woi911 VIP会员

    注册:
    2014-02-19
    帖子:
    283
    赞:
    59
    我的是这样的,请不要照着我的直接用,需要根据你的实际情况设置。

    我的环境是Linux+php5.4+Zenopcache+Memcached

    PHP:
    $config['cache']['enabled'] = true;
    $config['cache']['frontend'] = 'Core';
    $config['cache']['frontendOptions']['cache_id_prefix'] = 'xf_';
    $config['cache']['frontendOptions']['automatic_serialization'] = true;
    $config['cache']['cacheSessions'] = true;
    $config['cache']['backend']='Memcached';
    $config['cache']['backendOptions']=array(
      
    'compression'=>false,
      
    'servers' => array(
      array(
      
    'host'=>'127.0.0.1',
      
    'port'=>'11211',
      
    'persistent' => 'true'
      
    )
      )
    );

    记得重启php-fpm
    service php-fpm restart
     
    最后编辑: 2015-05-09
正在加载...