Bug? Memcache $cache->get/put and $ttl

Get help with installation and running phpBB 3.0.x here. Please do not post bug reports, feature requests, or MOD-related questions here.
Anti-Spam Guide
Forum rules
END OF SUPPORT: 1 January 2017 (announcement)
Locked
phantomk
Registered User
Posts: 1039
Joined: Wed Apr 14, 2004 5:32 am
Location: Canada Eh?
Name: Daniel Lee
Contact:

Bug? Memcache $cache->get/put and $ttl

Post by phantomk » Sat Jan 10, 2015 8:32 am

I think there is a bug when using Memcache and cache. For what ever reason, if I store something in the cache, for instance the following code:

Code: Select all

	$eve_players = $cache->get('eve_players');
	$eve_online = $cache->get('eve_online');

	if ($eve_players === false)
	{
		try {
			$pheal = new \Pheal\Pheal();

			$response = $pheal->serverScope->ServerStatus();
			$eve_online = (bool) $response->serverOpen;
			$eve_players = (int) $response->onlinePlayers;

			$cache->put('eve_online', $eve_online, 60);
			$cache->put('eve_players', $eve_players, 60);
		}
		catch (Exception $e) {
			$eve_online = false;
		}
	}

	if ($eve_online)
	{
		$eve_status = 'Players Online: ' . $eve_players;
	}
	else
	{
		$eve_status = 'Tranquility Server Down';
	}

	$eve_status .= '<br />Server Time: ' . date('H:i');
Even thought 60 seconds, even several mins/hours has gone by, the cache does not get refreshed as it never seems to "expire".

Using phpBB 3.0.12 w/ Memcache.

phantomk
Registered User
Posts: 1039
Joined: Wed Apr 14, 2004 5:32 am
Location: Canada Eh?
Name: Daniel Lee
Contact:

Re: Bug? Memcache $cache->get/put and $ttl

Post by phantomk » Sat Jan 10, 2015 11:57 pm

Found out why it was not using the TTL properly.

In order for the TTL to function, you must start your variable with an "_".

For example:

Code: Select all

			$cache->put('eve_online', $eve_online, 60);
			$cache->put('eve_players', $eve_players, 60);
Will store the data in the the global cache, which does not expire or only gets when cache is purged.

Code: Select all

			$cache->put('_eve_online', $eve_online, 60);
			$cache->put('_eve_players', $eve_players, 60);
This will store the data separate from the global cache.

Locked

Return to “[3.0.x] Support Forum”