XF 2.1 cache_id_prefix and lifetime for cache in XF2, like it was in XF 1.5??

sajal

Active member
Thanks a lot @Mike for your reply. I've noticed that, there a "Guest page caching". Was there anything like this in XF 1.5.X?

As we've almost 10M records, would you recommend enabling this "Guest page" caching on live site?
 

Mike

XenForo developer
Staff member
No, that feature is new in 2.1. It can help reduce load from guest views, though it really only relates to repeated viewing of particular pages. So in that regard, it would tend to be most beneficial on busy sites, particularly if there's a particular "hot" area.

The main caveat is that you generally don't want to use the same cache instance as you use for the "core" XF stuff, including sessions, as page caching can trigger quite a bit of data to be inserted. If that pushes the other data out, you're likely to have worse behavior (such as people getting logged out). Here's an example where someone has setup 2 Memcached instances to separate the caching: https://xenforo.com/community/threads/memcached-for-guest-page-caching.176404/
 

sajal

Active member
Ah thanks @Mike for the insightful reply. That makes sense. Between, I am trying to implement "Guest page caching" with following, but doesn't seem to be working as expected:


PHP:
$config['cache']['enabled'] = true;
$config['cache']['sessions'] = true;
$config['cache']['provider'] = 'Redis';
$config['cache']['config'] = [
    'host' => 'localhost',
    'port' => '6379'
];
$config['cache']['namespace'] = 'xf2_';

$config['pageCache']['enabled'] = true;
$config['pageCache']['lifetime'] = 300;
$config['cache']['context']['page']['provider'] = 'Redis';
$config['cache']['context']['page']['config'] = [
    'host' => 'localhost',
    'port' => '6379'
];

But, I can't see any "X-XF-Cache-Status: HIT" headers. Also, I insepcted cache keys in redis-cli, I don't see any key that has "page_" kind of prefix that should store the "whole guest page". Your thoughts?
 

Mike

XenForo developer
Staff member
If you see the header, it's working -- that's only returned when it's from the cache.

The actual cache keys used are more complex as there are changes to them from the underlying caching library we use.
 

Mike

XenForo developer
Staff member
Sorry, I misread.

I've tried exactly the config.php code you showed just modified to point at a local filesystem cache and the caching worked immediately as expected.
Code:
$config['cache']['context']['page']['provider'] = 'filesystem';
$config['cache']['context']['page']['config'] = [
    'directory' => \XF::getRootDirectory() . '/internal_data/pagecache'
];
(Plus the additional code you pasted. That's really just an example of how I modified it.)

I'm not clear on what would cause it not to be triggered short of the config.php changes not being applied. Your forum user also doesn't appear to be connected to the forum you're referring to, so I can't double check what I'm seeing.
 
Top