PHP code example of rl404 / simple-php-cache

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

    

rl404 / simple-php-cache example snippets



    etup 'default' cache
    $c = new Cache();


    // store a string
    $c->store('hello', 'Hello World!');

    // generate a new cache file with the name 'newcache'
    $c->setCache('newcache');

    // store an array
    $c->store('movies', array(
      'description' => 'Movies on TV',
      'action' => array(
        'Tropic Thunder',
        'Bad Boys',
        'Crank'
      )
    ));

    // get cached data by its key
    $result = $c->retrieve('movies');

    // display the cached array
    echo '<pre>';
    print_r($result);
    echo '<pre>';

    // grab array entry
    $description = $result['description'];

    // switch back to the first cache
    $c->setCache('mycache');

    // update entry by simply overwriting an existing key
    $c->store('hello', 'Hello everybody out there!');

    // erase entry by its key
    $c->erase('hello');


    $c->setCache('mycache')      // generate new file
      ->store('hello', 'world')  // store data string
      ->retrieve('hello');       // retrieve cached data


    // returns the count of erased entries
    echo $c->eraseExpired() . ' expired items erased!';