PHP code example of phoole / cache

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

    

phoole / cache example snippets


    // overwrite stampede defaults
    $cache = new Cache($fileAdatpor, [
        'stampedeGap' => 120,   // 120second
        'stampedePercent' => 2  // 2%
    ]);
    

    $cache = new Cache($fileAdaptor, [
        'distributedPercent' => 3,   // 3%, default is 5%
    ]);
    

  use Phoole\Cache\Cache;
  
  // using default adaptor and default settings
  $cache = new Cache();
  
  // get with default value 'phoole'
  $name  = $cache->get('name', 'phoole');
    
  // set cache
  $cache->set('name', 'wow');
  

  use Phoole\Cache\Cache;
  use Phoole\Cache\Adaptor\FileAdaptor;
 
  // use file adaptor and specific cache directory 
  $cache = new Cache(new FileAdaptor('/tmp/cache');
  

  use Phoole\Cache\Cache;
  use Phoole\Di\Container;
  use Phoole\Config\Config;
  
  // config cache in the container
  $container = new Container(new Config(
      'di.service' => [
          'cache' => Cache::class
      ],
  ));
  
  // get from container
  $cache = $container->get('cache');
  
  // or static FACADE way
  $cache = Container::cache();