Basic caching now integrated in trunk

Nephtali now facilitates basic page caching. ¬†Nephtali doesn’t actually implement the caching, but rather, it provides some easy hooks so you can use the caching library of your choice (APC, memcache, eaccelerator, etc.)

Here’s some example code from the Nephtali homepage which happens to use APC to accomplish the caching:

<?php
 
// Rest of code for index.php code-behind comes here, then caching below.
 
n\cache\register(
	$stage = n\constant\CACHE_FINAL,
	$fetch_func = function($markup)
	{
		$homepage_markup = apc_fetch("homepage", $success);
 
		if ($homepage_markup !== false)
		{
			return $homepage_markup;
		}
		else
		{
			return null;
		}
	},
	$save_func = function($markup)
	{
		apc_store("homepage", $markup, 3600);
	}
);
 
?>

So, pretty simple. ¬†Caching follows a registration paradigm just like the other features of Nephtali (ports, pipes, vals, etc.), and you merely tell Nephtali which stage of caching to intercept (for now, it’s just the final result, but more will come in the future) and which functions should handle getting and saving the cached results.