1. Go to this page and download the library: Download smart-php/super-cache 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/ */
smart-php / super-cache example snippets
uperCache\SuperCache as sCache;
//Saving cache value with a key
// sCache::cache('<key>')->set('<value>');
sCache::cache('myKey')->set('Key_value');
//Retrieving cache value with a key
echo sCache::cache('myKey')->get();
sCache::cache('myKey')->set('my_value')->lock();
//setting new value
sCache::cache('myKey')->set('new_value');
echo sCache::cache('myKey')->get(); //output : my_value
//unlocking
sCache::cache('myKey')->unlock()->set('new_value');
echo sCache::cache('myKey')->get(); //output : new_value
//options
sCache::cache('myKey')->set('my_value')->options([
'expiry' => time()+600, //time to expire
'lock' => true //alternative method to lock or unlock
'custom' => 'your customer attribute value'
]);
//isValid (To check for a valid key or to check whether it has expired or not)
sCache::cache('myKey')->isValid(); //true or false
//To get all option values
print_r(sCache::cache('myKey')->getOptions()); //array
//destroy
sCache::cache('myKey')->destroy();
//clearAll (Clear all cache values)
sCache::cache('myKey')->clearAll();
use SuperCache\SuperCache as sCache;
use SuperCache\State as State;
sCache::setPath('youCacheLocation');
Class MyClass
{
/**
* This trait class will bind data from cache to your class
*/
use State;
private $firstName;
private $lastName;
public function setName($firstName, $lastName)
{
$this->firstName = $firstName;
$this->lastName = $lastName;
}
public function getName()
{
return $this->firstName . " ". $this->lastName;
}
}
// Creating Object of your class
$myObject = new MyClass;
$myObject->setName("John", "Doe");
// Saving your object in SuperCache
sCache::cache('myObject')->set($myObject);
// Retrieving your object from Cache
$cacheObject = sCache::cache('myObject')->get();
echo $myObject->getName();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.