PHP code example of sinsquare / silex-doctrine-cache-provider

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

    

sinsquare / silex-doctrine-cache-provider example snippets




use SinSquare\Cache\DoctrineCacheServiceProvider;

$container = new Container();
$container['doctrine.cache.options'] = array(
    'providers' => array(
        'cache_name_1' => array(
            'type' => 'void',
        ),
    ),
);

$container->register(new DoctrineCacheServiceProvider());



$container['doctrine.cache.options'] = array(
    'providers' => array(
        'cache_name_1' => array(
            'type' => 'void',
        ),
    ),
);

$container->register(new DoctrineCacheServiceProvider());

$cache = $container['doctrine.caches']['cache_name_1'];
//OR
$cache = $container['doctrine.caches.cache_name_1'];



$container['doctrine.cache.options'] = array(
    'providers' => array(
        'cache' => array(
            'type' => 'apc'
        ),
    ),
);



$container['doctrine.cache.options'] = array(
    'providers' => array(
        'cache' => array(
            'type' => 'apcu'
        ),
    ),
);



$container['doctrine.cache.options'] = array(
    'providers' => array(
        'cache' => array(
            'type' => 'array'
        ),
    ),
);



$container['doctrine.cache.options'] = array(
    'providers' => array(
        'cache' => array(
            'type' => 'chain',
            'caches' => array('cache_1', 'cache_2')
        ),
        'cache_1' => array(
            'type' => 'array'
        ),
        'cache_2' => array(
            'type' => 'apc'
        ),
    ),
);



$container['doctrine.cache.options'] = array(
    'providers' => array(
        'cache' => array(
            'type' => 'filesystem',
            'directory' => 'dir',
			'extension' => 'value' //optional
			'umask' => 'value' //optional
        )
    ),
);



$container['doctrine.cache.options'] = array(
    'providers' => array(
        'cache' => array(
            'type' => 'filesystem',
            'directory' => 'dir',
			'extension' => 'value' //optional
			'umask' => 'value' //optional
        )
    ),
);



$container['doctrine.cache.options'] = array(
    'providers' => array(
        'cache' => array(
            'type' => 'phpfile',
            'directory' => 'dir',
			'extension' => 'value' //optional
			'umask' => 'value' //optional
        )
    ),
);



$container['doctrine.cache.options'] = array(
    'providers' => array(
        'cache' => array(
            'type' => 'memcache',
            'host' => 'host',
			'port' => 'port'
        )
    ),
);



$container['doctrine.cache.options'] = array(
    'providers' => array(
        'cache' => array(
            'type' => 'memcached',
            'host' => 'host',
			'port' => 'port'
        )
    ),
);



$container['doctrine.cache.options'] = array(
    'providers' => array(
        'cache' => array(
            'type' => 'void'
        )
    ),
);





namespace Your\Name\Space;

use Doctrine\Common\Cache\CacheProvider;

class MyCustomCache extends CacheProvider
{
//class body with the 


//you have to define this BEFORE you get a new cache, preferably before registering the provider
$container['doctrine.cache.factory.customcache'] = $container->protect(function ($cacheOptions) use ($container) {

	$namespace = $cacheOptions["namespace"];

	//

	return new MyCustomCache();

});



$container['doctrine.cache.options'] = array(
    'providers' => array(
        'cache' => array(
            'type' => 'customcache'
        )
    ),
);

//getting the cache is the same as before