1. Go to this page and download the library: Download xmadmax/xcache library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
xmadmax / xcache example snippets
{
" "xmadmax/xcache": "3.*"
}
}
// First of all, define the xcacheconf configuration dir location (the name of this file will be ever xcacheconf.json)
define("XCACHE_CONFPATH",__DIR__)
// Include composer autoload
class myClass extends myMasterClass
{
public function myMethod($params)
{
.
.
.
return $something
}
}
e("XCACHE_CONFPATH",'/var/www/myApp/conf'); // Wherever is the xcacheconf.json file
class myClass
{
use XCacheDriver; // Include this line after class definition
public function __construct()
{
// This makes the magic happen
$this->xCachePass();
}
public function _myMethod($params) // Add a single '_' before the name of the method
{
.
.
.
return $something
}
}
$params = 'a string, an array, an object ...';
$myClass = new myClass();
$result = $myClass->myMethod($params);
e("XCACHE_CONFPATH",'/var/www/myApp/conf'); // Wherever is the xcacheconf.json file
class myClass
{
use XCacheDriver; // Include this line after class definition
public function myMethod($params)
{
.
.
.
return $something
}
}
$myClass = new myClass();
$params = array('value1','value2');
$result = $myClass->xCacheMethod("cache_methods","myClass_myMethod",md5('myClass_myMethod'.json_encode($params)),$myClass,'myMethod',$params);
e("XCACHE_CONFPATH",'/var/www/myApp/conf'); // Wherever is the xcacheconf.json file
class myClass
{
use XCacheDriver; // Include this line after class definition
public function myMethod($params)
{
.
.
.
return $something
}
}
$myClass = new myClass();
$result = $myClass->myMethod($params);
$myClass->xCacheValue("cache_values","myResult",md5('myResult'),$result);