1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How does caching work?

Discussion in 'XenForo Questions and Support' started by Jaxel, Nov 24, 2011.

  1. Jaxel

    Jaxel Well-Known Member

    I installed XF1.1 today and added to my config.php:
    Code:
    $config['cache']['enabled'] = true;
    $config['cache']['frontend'] = 'Core';
    $config['cache']['frontendOptions'] = array(
        'caching'                    => true,
        'lifetime'                    => 3600,
        'cache_id_prefix'            => 'xf_'
    );
    $config['cache']['cacheSessions'] = true;
    I have eAccelerator installed on my server... is this all I need to do? I then enabled the two options 'Minify CSS' and 'Fetch public templates as files'. These options are supposed to make my website FASTER, is that correct?

    Since doing all these changes, my website is running slower than ever. The number of queries per page is indeed lower, but timings are higher. Did I do something wrong?
     
  2. Brogan

    Brogan XenForo Moderator Staff Member

    M@rc and Walter like this.
  3. Jaxel

    Jaxel Well-Known Member

    Thanks Brogan, but that only removes 2 lines from the code I posted, and doesn't answer my question.
     
  4. Mike

    Mike XenForo Developer Staff Member

    You need to define a backend as well.
     
  5. Jaxel

    Jaxel Well-Known Member

    For both options? Even for Fetch public templates as files?
     
  6. Deebs

    Deebs Well-Known Member

    No, as long as you have an opcode cache installed then Fetch public templates as files? will get cached as they are saved as PHP files.

    Here is my config:
    Code:
    // Setup the frontend caching system
    $config['cache']['enabled'] = true;
    $config['cache']['frontend'] = 'Core';
    $config['cache']['frontendOptions'] = array('caching'  =>  true,
                                                'automatic_serialization' => true,
                                                'lifetime'    => 1800,
                                                'write_control' => true,
                                                'cache_id_prefix' => 'fh_xf_'
    );
     
    // Libmemcached setup
    $config['cache']['backend'] = 'Libmemcached';
    $config['cache']['backendOptions'] = array(
                            'servers' => array(
                                    'host' => 'localhost',
                                    'port' => 11211, 'persistent' => true,
                                    'weight' => 1, 'timeout' => 5,
                                    'retry_interval' => 15,
                                    'status' => true,
                                    'failure_callback' => '' ));
     
    // Cache sessions in the backend
    $config['cache']['cacheSessions'] = true;
     
  7. Mikey

    Mikey Well-Known Member

    this is what I have.

    Code:
     
    ## Caching
    #  http://xenforo.com/community/threads/speed-up-your-board-caching.5699/
    #  http://xenforo.com/community/threads/tip-use-apc.6456/
    $config['cache']['enabled'] = 'true';
    $config['cache']['cacheSessions'] = true; // from 1.1 beta 4 onwards
    $config['cache']['frontend'] = 'Core';
    $config['cache']['frontendOptions'] = array(
                                           'caching'                      => true,
                                           'automatic_serialization'      => true,
                                            'lifetime'                      => 1800,
                                            'cache_id_prefix' => 'tgd_'
    );
    $config['cache']['backend'] = 'Apc';
    
     
  8. Jaxel

    Jaxel Well-Known Member

    Okay... I had my host install memcache on my server... how do I confirm that it's working?

    Code:
    $config['enableGzip'] = false;
     
    $config['cache']['enabled'] = true;
    $config['cache']['frontend'] = 'Core';
    $config['cache']['frontendOptions'] = array(
        'caching'                    => true,
        'lifetime'                    => 3600,
        'cache_id_prefix'            => 'xf_'
    );
    $config['cache']['cacheSessions'] = true;
     
    $config['cache']['backend'] = 'Memcached';
    $config['cache']['backendOptions'] = array(
        'compression' => false,
        'servers' => array(
            array(
                'host' => 'localhost',
                'port' => 11211,
                'persistent' => true,
                'weight' => 1,
                'timeout' => 5,
                'retry_interval' => 15,
                'status' => true,
            )
        )
    );
     
  9. Deebs

    Deebs Well-Known Member

    You can telnet to 11211 from your host and then type "stats". You will see counters which will indicate whether it is working or not.
     
  10. Jaxel

    Jaxel Well-Known Member

    I ran:
    Code:
    ps aux | grep memcached
    and got back:
    But I have no idea what that stuff means.
     
  11. RobParker

    RobParker Well-Known Member

    Could someone post what my config should look like to use APC as well as the frontend caching, etc? Does doing both cause any problems?
     
  12. TazDevilLooney

    TazDevilLooney Active Member

    telnet 127.0.0.1 11211
    stats

    memcache.png

    (11211) Does this port need to be opened up externaly to the internet for this to work or is it an internal server side thing?
     
  13. Jaxel

    Jaxel Well-Known Member

    What the hell does all that crap mean? Does that mean its working?
     
    8thos likes this.
  14. TazDevilLooney

    TazDevilLooney Active Member

    STAT get_hits 6567960
    STAT get_misses 6484
    STAT delete_misses 2
    STAT delete_hits 437

    Yep looks good to me. If it wasn't working properly then you wouldn't have any hits. (y)
     
  15. steel_curtain

    steel_curtain Well-Known Member

    Yep you have stored items, open connections, successful requests, etc... Not a pro but I can tell you it's working. Some basics on the stats below, and you can read more here.

    pid - Process id of this server process
    uptime - Number of seconds this server has been running
    time - current UNIX time according to the server
    version - Version string of this server
    pointer_size - Default size of pointers on the host OS
    rusage_user - Accumulated user time for this process (seconds:microseconds)
    rusage_system - Accumulated system time for this process (seconds:microseconds)
    curr_items - Current number of items stored by the server
    total_items - Total number of items stored by this server ever since it started
    bytes - Current number of bytes used by this server to store items
    curr_connections - Number of open connections
    total_connections - Total number of connections opened since the server started running
    connection_structures - Number of connection structures allocated by the server
    cmd_get - Cumulative number of retrieval requests
    cmd_set - Cumulative number of storage requests
    get_hits - Number of keys that have been requested and found present
    get_misses - Number of items that have been requested and not found
    evictions - Number of valid items removed from cache to free memory for new items
    bytes_read - Total number of bytes read by this server from network
    bytes_written - Total number of bytes sent by this server to network
    limit_maxbytes - Number of bytes this server is allowed to use for storage.
    threads - Number of worker threads requested.
     
  16. Deebs

    Deebs Well-Known Member

    Absolutely not! Keep it firewalled off from the internet. You only need to be able to access that port locally and if you have any additional servers then you need whitelist their IP addresses as well.
     
  17. TazDevilLooney

    TazDevilLooney Active Member

    Guess i must refrain from doing that then. Thanks for the info Deebs. (y)
     
  18. TheBigK

    TheBigK Well-Known Member

    I just enabled caching and it seems to have affected the user session logout time. Is that common?
     
  19. Deebs

    Deebs Well-Known Member

    If you have enabled Session Caching and users are being logged out randomly etc then you are most likely running out of space in the cache and variables are being evicted.
     
  20. TheBigK

    TheBigK Well-Known Member

    I just found that caching itself works fine. If I disable caching for user sessions, then the user quicker logout problem disappears. Does it really make a lot of difference to store user sessions in cache?
     

Share This Page