WinCache ACM backend

Discussion of general topics related to the new version and its place in the world. Don't discuss new features, report bugs, ask for support, et cetera. Don't use this to spam for other boards or attack those boards!
Forum rules
Discussion of general topics related to the new release and its place in the world. Don't discuss new features, report bugs, ask for support, et cetera. Don't use this to spam for other boards or attack those boards!
ChrisTX
Registered User
Posts: 6
Joined: Sat Nov 20, 2010 10:52 pm

WinCache ACM backend

Post by ChrisTX »

Hello,

I'm not exactly sure where to post this, but I made a ACM backend for Windows Cache for PHP (wincache) and wanted to share it. I wasn't able to test this on anything bigger than my own newly-setup forum, but it seems to be loaded fine, and I couldn't spot any issues with it so far. Since WinCache works pretty similar to the APC/XCache, I don't expect there to be any either.

Hoping it might be useful for somebody.

Chris
Attachments
acm_wincache.zip
WinCache ACM backend.
(811 Bytes) Downloaded 743 times
User avatar
bantu
3.0 Release Manager
3.0 Release Manager
Posts: 557
Joined: Thu Sep 07, 2006 11:22 am
Location: Karlsruhe, Germany
Contact:

Re: WinCache ACM backend

Post by bantu »

Hello,

I think this could even go into 3.0.9-RC1 if it is working. :-)

Thanks
- bantu
ChrisTX
Registered User
Posts: 6
Joined: Sat Nov 20, 2010 10:52 pm

Re: WinCache ACM backend

Post by ChrisTX »

Hello,
bantu wrote:I think this could even go into 3.0.9-RC1 if it is working. :-)
That'd be great. :)
Is there any way I can test it more deeply than just being able to tell that my own forum can run it without any errors? I took a look into the tests at phpBB's git, but I couldn't see any ACM-specific tests there. But as I said, WinCache works very similar to APC (of which's acm I also forked this), the only real difference being that wincache_ucache_get() ( apc_fetch()'s equivalent ) returns an empty array on failure, and not FALSE, thus I implemented _isset ( wincache_ucache_exists() ) as well.

- Chris
ToonArmy
Registered User
Posts: 335
Joined: Fri Mar 26, 2004 7:31 pm
Location: Bristol, UK
Contact:

Re: WinCache ACM backend

Post by ToonArmy »

I have an implementation of this sat in my repository, I've just never got around to testing it. https://github.com/cs278/phpbb3/compare ... ncache-acm
Chris SmithBlogXMOOhlohArea51WikiNo support via PM/IM
Image
ChrisTX
Registered User
Posts: 6
Joined: Sat Nov 20, 2010 10:52 pm

Re: WinCache ACM backend

Post by ChrisTX »

ToonArmy wrote:I have an implementation of this sat in my repository, I've just never got around to testing it. https://github.com/cs278/phpbb3/compare ... ncache-acm
Our implementations are pretty much the same, only you made _read return false on failure, like APC would do. I don't think however that you need to implement _isset in that case ( at least judging by how I understood acm_memory's interna, might be wrong ).

EDIT: Actually modifying _read should be better than implementing _isset, considering it won't require WinCache to lookup the $key value twice. I updated my pull request accordingly. (also tested this patch, it works fine, too.)

EDIT2: I missed the most obvious way of testing the ACM. By using the wincache.php that comes with WinCache, you can view statistics on the cache usage.
Attachments
wincache-stats.png
WinCache stats
(139.13 KiB) Downloaded 3847 times
igorw
Registered User
Posts: 500
Joined: Thu Jan 04, 2007 11:47 pm

Re: WinCache ACM backend

Post by igorw »

Here is the diff between the implementations. a is by ChrisTX, b is by ToonArmy.

Code: Select all

$ diff -u a.txt b.txt 
--- a.txt	2010-11-24 15:02:10.000000000 +0100
+++ b.txt	2010-11-24 15:02:16.000000000 +0100
@@ -3,7 +3,7 @@
 *
 * @package acm
 * @version $Id$
-* @copyright (c) 2010 phpBB Group
+* @copyright (c) 2005, 2009, 2010 phpBB Group
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
 *
 */
@@ -23,13 +23,18 @@
 }
 
 /**
-* ACM for WinCache
+* ACM for Wincache
 * @package acm
 */
 class acm extends acm_memory
 {
 	var $extension = 'wincache';
 
+	function acm()
+	{
+		parent::acm_memory();
+	}
+
 	/**
 	* Purge cache data
 	*
@@ -37,9 +42,10 @@
 	*/
 	function purge()
 	{
-		wincache_ucache_clear();
-
+		// Run before for XCache, if admin functions are disabled it will terminate execution
 		parent::purge();
+
+		wincache_ucache_clear();
 	}
 
 	/**
@@ -52,7 +58,9 @@
 	function _read($var)
 	{
 		$success = false;
+	
 		$result = wincache_ucache_get($this->key_prefix . $var, $success);
+
 		return ($success) ? $result : false;
 	}
 
@@ -81,6 +89,18 @@
 	{
 		return wincache_ucache_delete($this->key_prefix . $var);
 	}
+
+	/**
+	* Check if a cache var exists
+	*
+	* @access protected
+	* @param string $var Cache key
+	* @return bool True if it exists, otherwise false
+	*/	
+	function _isset($var)
+	{
+		return wincache_ucache_exists($this->key_prefix . $var);
+	}
 }
 
-?>
+?>
\ No newline at end of file
They are almost identical now. Since ToonArmy's appears to be a tiny bit more complete, we might want to just go with that. Some further testing would be great though.

In terms of unit tests I don't think it's possible to test this cleanly in 3.0, because every cache class has the same name. There is a refactoring planned for 3.1 (I've started some work on it: https://github.com/igorw/phpbb3/compare ... m-extended) that will allow to load different cache plugins in order to test them.
ChrisTX
Registered User
Posts: 6
Joined: Sat Nov 20, 2010 10:52 pm

Re: WinCache ACM backend

Post by ChrisTX »

As I said, it is less efficient to implement _isset under these conditions, because that will cause serveral doubled queries, i.e. in destroy() of acm_memory, the _exists() function ( which refers to the _isset one ) will be called before _delete() and if it fails - and only then - it will skip the rest. However, wincache_ucache_delete() does the lookup anyway, and if it fails there (= it doesn't exist), FALSE is returned. Similarly, get() would be made less efficient the same way. I didn't implement _isset() on purpose, or actually, I first had it, but then realised it being like this. Implementing _read with a return of the success status ( opposed to the empty array it would return otherwise ), is more efficient, since the actual lookup has only to be made once, and not in wincache_ucache_exists() and the function you call then.

Considering testing, it would only be necessary to verify that the actual ACM code has no issues. When implementing that reflected change yesterday, I was a bit distracted and made this typo, which would have led to make wincache's stats show properly ( since the request was made) but then to not actually use the cache. The rest (deletions, requests, writing, purging) is done properly, which can be verified - at least for wincache, for other systems I do not know - using the stats site.
igorw
Registered User
Posts: 500
Joined: Thu Jan 04, 2007 11:47 pm

Re: WinCache ACM backend

Post by igorw »

Okay, I see. What about the "Run before for XCache, if admin functions are disabled it will terminate execution" comment in purge() though? I'm not sure what Chris (ToonArmy) meant exactly, since it is kind of vague. But that may still need adjusting.
ChrisTX
Registered User
Posts: 6
Joined: Sat Nov 20, 2010 10:52 pm

Re: WinCache ACM backend

Post by ChrisTX »

I do, he implemented the ACM similary to me, that is by branching an existing backend. I started off acm_apc, he started off acm_xcache. If you'd look inside the file, you can also see the comment there, it's a left-over he forgot to remove. Same goes to the call to parent::acm_memory() in the constructor, in acm_xcache, that has a purpose; however, here it's not needed.

That's also the reason why the order of our parent::purge / wincache_ucache_clear(); calls in the purge is inverted, acm_apc and acm_xcache do it differently ( though it doesn't matter for wincache ).
igorw
Registered User
Posts: 500
Joined: Thu Jan 04, 2007 11:47 pm

Re: WinCache ACM backend

Post by igorw »

I am really failing today, it seems. :oops: :roll:
Post Reply