XF 2.1 Guest page caching

Nirjonadda

Well-known member
I am getting error with Guest page caching. Issue with this code. Please can you let me know that how can fix this problem?

Code:
// START Guest page caching //
//$config['pageCache']['enabled'] = true;
//$config['cache']['context']['page']['provider'] = 'Redis';
//$config['cache']['context']['page']['config'] = ['127.0.0.1'];
// END Guest page caching //

Server error log:

Code:
RedisException: php_network_getaddresses: getaddrinfo failed: Name or service not known src/XF/CacheFactory.php:226

Generated by: Unknown account Nov 13, 2019 at 9:43 PM

Stack trace

#0 src/XF/CacheFactory.php(226): Redis->connect('', 6379, G)
#1 src/XF/CacheFactory.php(79): XF\CacheFactory->createRedisCache(Array)
#2 src/XF/CacheFactory.php(34): XF\CacheFactory->instantiate('Redis', Array)
#3 src/XF/App.php(639): XF\CacheFactory->create('Redis', Array)
#4 src/XF/Container.php(228): XF\App->XF\{closure}('page', Array, Object(XF\Container))
#5 src/XF/App.php(2346): XF\Container->create('cache', 'page')
#6 src/XF/Pub/App.php(54): XF\App->cache('page', false)
#7 src/XF/Container.php(28): XF\Pub\App->XF\Pub\{closure}(Object(XF\Container))
#8 src/XF/Pub/App.php(674): XF\Container->offsetGet('pageCache')
#9 src/XF/Pub/App.php(102): XF\Pub\App->pageCache()
#10 src/XF/App.php(2180): XF\Pub\App->start(true)
#11 src/XF.php(391): XF\App->run()
#12 index.php(20): XF::runApp('XF\\Pub\\App')
#13 {main}

-------------

Previous ErrorException: [E_WARNING] Redis::connect(): php_network_getaddresses: getaddrinfo failed: Name or service not known - src/XF/CacheFactory.php:226
#0 [internal function]: XF::handlePhpError(2, '[E_WARNING] Red...', '/home/nadda/pub...', 226, Array)
#1 src/XF/CacheFactory.php(226): Redis->connect('', 6379, G)
#2 src/XF/CacheFactory.php(79): XF\CacheFactory->createRedisCache(Array)
#3 src/XF/CacheFactory.php(34): XF\CacheFactory->instantiate('Redis', Array)
#4 src/XF/App.php(639): XF\CacheFactory->create('Redis', Array)
#5 src/XF/Container.php(228): XF\App->XF\{closure}('page', Array, Object(XF\Container))
#6 src/XF/App.php(2346): XF\Container->create('cache', 'page')
#7 src/XF/Pub/App.php(54): XF\App->cache('page', false)
#8 src/XF/Container.php(28): XF\Pub\App->XF\Pub\{closure}(Object(XF\Container))
#9 src/XF/Pub/App.php(674): XF\Container->offsetGet('pageCache')
#10 src/XF/Pub/App.php(102): XF\Pub\App->pageCache()
#11 src/XF/App.php(2180): XF\Pub\App->start(true)
#12 src/XF.php(391): XF\App->run()
#13 index.php(20): XF::runApp('XF\\Pub\\App')
#14 {main}

Request state

array(4) {
  ["url"] => string(34) "/index.php?forums/65/create-thread"
  ["referrer"] => bool(false)
  ["_GET"] => array(1) {
    ["forums/65/create-thread"] => string(0) ""
  }
  ["_POST"] => array(0) {
  }
}
 
I think this:
Code:
$config['cache']['context']['page']['config'] = ['127.0.0.1'];

should be:
Code:
$config['cache']['context']['page']['config'] = [
        'host' => '127.0.0.1',
        'port' => 6379
       ];
 
Now with this code User logout will be show Security error occurred. Please press back, refresh the page, and try again with Guest page caching. Please can you let me know that how to fixing this issue? I am using phpredis 5.1.1 with Redis Version 3.2.12

ScreenShot01281.webp

Issue happened with this code:

Code:
// START Guest page caching //
$config['pageCache']['enabled'] = true;
$config['cache']['context']['page']['provider'] = 'Redis';
$config['cache']['context']['page']['config'] = [
        'host' => '127.0.0.1',
        'port' => 6379
       ];
// END Guest page caching //

Full Redis Cache code:

Code:
// START Redis configuration //
$config['cache']['enabled'] = true;
$config['cache']['sessions'] = true;
$config['cache']['namespace'] = 'xfredis_';

$config['cache']['provider'] = 'SV\RedisCache\Redis';
$config['cache']['config'] = array(
'server' => '127.0.0.1',
'port' => 6379,
'connect_retries' => 2,
'use_lua' => true,
'compress_data' => 6,
'read_timeout' => 1,
'timeout' => 1,
'serializer' => 'igbinary',
//        'serializer' => 'php',
'persistent' => true,
);
// END Redis configuration //

// START Guest page caching //
$config['pageCache']['enabled'] = true;
$config['cache']['context']['page']['provider'] = 'Redis';
$config['cache']['context']['page']['config'] = [
        'host' => '127.0.0.1',
        'port' => 6379
       ];
// END Guest page caching //

// START CSS caching //
$config['cache']['context']['css'] = [
            'namespace' => 'sv',
            'provider' => 'SV\RedisCache\Redis',
            'config' => [
'server' => '127.0.0.1',
'port' => 6379,
            ],
        ];
// END CSS caching //

// START Mobile detection with full page caching //
$config['pageCache']['onSetup'] = function (\XF\PageCache $pageCache) {
    $pageCache->setCacheIdGenerator(function(\XF\Http\Request $request) {
        return \SV\BrowserDetection\CacheHelper::getPageCacheId($request);
    });
};
// END Mobile detection with full page caching //
 
// START Guest page caching //
.....
$config['cache']['context']['page']['provider'] = 'Redis';

should be:
$config['cache']['context']['page']['provider'] = 'SV\RedisCache\Redis';
 
// START Guest page caching //
.....
$config['cache']['context']['page']['provider'] = 'Redis';

should be:
$config['cache']['context']['page']['provider'] = 'SV\RedisCache\Redis';

Checked with both code but User logout will be show Security error occurred. Please press back, refresh the page, and try again. User will be logged out but this popup showing and does not Redirects to logout..
 
FYI, Xon's redis cache addon doesn't do anything with guest page caching, so you can use 'Redis' as provider.

Try this:
Code:
// START Guest page caching //
$config['pageCache']['enabled'] = true;
$config['cache']['context']['page']['provider'] = 'Redis';
$config['cache']['context']['page']['config'] = [
        'host' => '127.0.0.1',
        'port' => 6379,
        'connect_retries' => 2,
        'use_lua' => true,
        'compress_data' => 6,
        'read_timeout' => 1,
        'timeout' => 1,
        'serializer' => 'igbinary',
        'persistent' => true
       ];
// END Guest page caching //
 
Does not work. Still issue User logout will be show Security error occurred. Please press back, refresh the page, and try again. User will be logged out but this popup showing and does not Redirects to logout.
 
I have the same problem.
With guest page caching enabled there are problems when a user logs out:
  • Sometimes when the user does a logout, the page still says the user is logged in (but he isn't). When you click on something that needs a permission, you will get a security error.
  • Sometimes a security error appears direct after logout, telling to refresh.
 
I have the same problem.
With guest page caching enabled there are problems when a user logs out:
  • Sometimes when the user does a logout, the page still says the user is logged in (but he isn't). When you click on something that needs a permission, you will get a security error.
  • Sometimes a security error appears direct after logout, telling to refresh.

Here the same - only on Chrome, not Firefox.
 
I believe there have been other reports of this:

We're unable to reproduce an issue and the behaviour seems inconsistent with how XF behaves.

If it is the same issue, you will need to look at the "Network" tab of your browser's console. The request that is logged when the page reloads after logging out (in the case of the issue we have seen) is that it appears to be loading a cached page from somewhere, but it does not appear to be loading from our guest page cache. Notably, in the other thread, it doesn't contain any of our cache hit headers and it also seems to be receiving a 304 response - this is not a response code that XF sends when rendering any content pages in XF.

We don't know what the issue is, but at this time it does not appear to be caused by XF.
 
Looks like the same issue. For me it is reproducible, but I don't know what is causing this.
When I press logout, the page shows that the user is still logged in.
I checked the Network tab:
status: 304
cache-control: private, no-cache, max-age=0

If I wait a few seconds and refresh, then the normal 'guest' page is displayed
 
Last edited:
I got apache error 400
I dont using xons rediscache, and this error only is on Chrome Version 78.0.3904.97 (Offizieller Build) (64-Bit)

After Logout, and then refresh the Page (F5) this error in chromes consoleview

Failed to load resource: the server responded with a status of 400 ()
.
/account/visitor-menu?_xfRequestUri=%2F&_xfWithData=1&_xfToken=1573896295%2Cd268b0a46997d9bd879b6126788c6f22&_xfResponseType=json:1 Failed to load resource: the server responded with a status of 400 ()

EDIT:
Adding Cacheconfig
$config['cache']['enabled'] = true;
$config['pageCache']['enabled'] = true;
$config['pageCache']['recordSessionActivity'] = true;
$config['cache']['context']['page']['namespace'] = 'xfredispagecache_';
$config['cache']['context']['page']['provider'] = 'Redis';
$config['cache']['context']['page']['config'] = [
'host' => '127.0.0.1',
'port' => 6379,
'database' => 0,
'compress_data' => 6
];

hth
 
Last edited:
It's the same issue as some other people have, including me. You can read also this thread but it won 't help you. We didn't find solution. For now page caching is disabled.
 
Back
Top Bottom