PHP code example of stefangabos / zebra_cache

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

    

stefangabos / zebra_cache example snippets




// instantiate the library
$cache = new Zebra_Cache('path/to/store/cache-files/');

// if a cached, non-expired value for the sought key does not exist
if (!($some_data = $cache->get('my-key'))) {

    // do whatever you need to retrieve data
    $some_data = 'get this data';

    // cache the values for one hour (3600 seconds)
    $cache->set('my-key', $some_data, 3600);

}

// $some_data now holds the values, either fresh or from cache

if ($cached_info = $cache->has('my-key')) {

    // will output something in the  likes of
    //  Array (
    //    'path'     => '',  //  path to the cache file
    //    'timeout'  => '',  //  the number of seconds the cache was supposed to be valid
    //    'ttl'      => '',  //  number of seconds remaining until the cache expires
    //  )

    print_r('<pre>');
    print_r($cached_info);

}

$cache->delete('my-key');