PHP code example of mactronique / phpcache

1. Go to this page and download the library: Download mactronique/phpcache 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/ */

    

mactronique / phpcache example snippets

 shell
php composer.phar 
 php
$config = array(
	"host" => "127.0.0.1",
	"port" => "",
	"password" => "",
	"database" => "",
	"timeout" => 1,
	"read_write_timeout" => 1
);
 php
$config = array(
	"host" => "127.0.0.1",
	"port" => "",
	"password" => "",
	"database" => "",
	"timeout" => 1
);
 php
$config = array(
	"host" => "127.0.0.1",
	"port" => 11211,
	"sharing" => 100
);
 php
use Mactronique\PhpCache\Service\PhpCache;
use Mactronique\PhpCache\Driver\NullDriver;

class myService
{
	private $cache
	public function __construct(PhpCache $cache = null)
	{
		if (null === $cache) {
			$cache = new PhpCache();
			$cache->registerDriver(new NullDriver());
		}
		$this->cache = $cache;
	}

	public function myAction()
	{
		/*
		You can use the cache but never key exist and all get return null.
		*/
		$val = $this->cache->get('key');
		[...]
	}
}