PHP code example of pcelta / doctrine-cache-factory

1. Go to this page and download the library: Download pcelta/doctrine-cache-factory 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/ */

    

pcelta / doctrine-cache-factory example snippets



use Pcelta\Doctrine\Cache\Factory;

$factory = new Factory();
$cacheSettings [
    'adapter'           => 'Memcache',
    'adapter_namespace' => '\Doctrine\Common\Cache\%sCache',
    'host'              => '127.0.0.1',
    'port'              => 11211,
];

$cacheProvider = $factory->create($cacheSettings);



use Pcelta\Doctrine\Cache\Factory;

$factory = new Factory();
$cacheSettings [
    'adapter'       => 'Array',
];

$cacheProvider = $factory->create($cacheSettings);



use Pcelta\Doctrine\Cache\Factory;

$factory = new Factory();
$cacheSettings [
    'adapter_name' => 'Memcache',
    'host'         => '127.0.0.1',
    'port'         => 11211,
];

$cacheProvider = $factory->create($cacheSettings);



use Pcelta\Doctrine\Cache\Factory;

$factory = new Factory();
$cacheSettings [
    'adapter_name' => 'Memcached',
    'host'         => '127.0.0.1',
    'port'         => 11211,
];

$cacheProvider = $factory->create($cacheSettings);



use Pcelta\Doctrine\Cache\Factory;

$factory = new Factory();
$cacheSettings [
    'adapter_name' => 'Redis',
    'host'         => '127.0.0.1',
    'port'         => 11211,
];

$cacheProvider = $factory->create($cacheSettings);



use Pcelta\Doctrine\Cache\Factory;

$factory = new Factory();
$cacheSettings [
    'adapter_name' => 'Memcache',
    'host'         => '127.0.0.1',
    'port'         => 11211,
];

$cacheProvider = $factory->create($cacheSettings);

$cacheProvider->save('your-key', 'your-data');
$data = $cacheProvider->fetch('your-key');

echo $data; // your-data



$memcache = new Memcache(); // it's bad to uncouple
$memcache->connect('memcache_host', 11211);

$cacheDriver = new \Doctrine\Common\Cache\MemcacheCache();
$cacheDriver->setMemcache($memcache);
$cacheDriver->save('cache_id', 'my_data');



$factory = new \Pcelta\Doctrine\Cache\Factory();
$cacheSettings [
    'adapter_name' => 'Memcache', // it's much better
    'host'         => '127.0.0.1',
    'port'         => 11211,
];

$cacheProvider = $factory->create($cacheSettings); 
$cacheProvider->save('cache_id', 'your-data');