Warning : At the moment, It is not possible to store resources, callbacks or objects using xcache_* functions.

Examples:

Simple Counter

This guest book has been visited <?phpechoxcache_inc("count");?> times.

Advanced Counter

<?phpif(!xcache_isset("count")){xcache_set("count",load_count_from_mysql());}?>
This guest book has been visited <?phpecho$count=xcache_inc("count");?> times.
<?php// save every 100 hits
if(($count%10)==100){save_count_to_mysql($count);}?>

Cacher

<?phpdefine(TMPDIR,'/tmp');functionload_abc_data(){if(xcache_isset("abc_data")){returnxcache_get("abc_data");}// it worth a lock here to avoid useless yet harmful concurrent load from any slow backend (backend=mysql here).
$fp=fopen(TMPDIR."/abc_data.lock","w");flock($fp,LOCK_EX);// check AGAIN after we get the lock
if(xcache_isset("abc_data")){fclose($fp);returnxcache_get("abc_data");}mysql_query....andget$dataxcache_set("abc_data",$data,120);// save for 2 minutes
fclose($fp);return$data;}?>