PHP code example of openclassrooms / cache-bundle

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

    

openclassrooms / cache-bundle example snippets


// in AppKernel::registerBundles()
$bundles = array(
    // ...
    new OpenClassrooms\Bundle\CacheBundle\OpenClassroomsCacheBundle(),
    // ...
);

$cache = $container->get('openclassrooms.cache.cache');

$cache->fetch($id);
$cache->fetchWithNamespace($id, $namespaceId);
$cache->save($id, $data);
$cache->saveWithNamespace($id, $data, $namespaceId);
$cache->invalidate($namespaceId);


$cacheProvider = $container->get('openclassrooms.cache.cache_provider');

$builder = $container->get('openclassrooms.cache.cache_provider_builder');

// Redis
$cacheProvider = $builder
    ->create(CacheProviderType::REDIS)
    ->withHost('127.0.0.1')
    ->withPort(6379) // Default 6379
    ->withTimeout(0.0) // Default 0.0
    ->build();