PHP code example of kminek / cache

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

    

kminek / cache example snippets


/**
 * @param string $key
 * @param mixed  $default
 *
 * @return mixed
 */
function cache_get($key, $default = null);

/**
 * @param string   $key
 * @param mixed    $value
 * @param null|int $ttl
 *
 * @return bool
 */
function cache_set($key, $value, $ttl = null);

/**
 * @param string $key
 *
 * @return bool
 */
function cache_delete($key);

/**
 * @return bool
 */
function cache_clear();



$cachedData = cache_get('cachedData');

if (!$cachedData) {
    echo 'Saving cache...' . PHP_EOL;
    cache_set('cachedData', array('lorem', 'ipsum'), 5 * 60); // 5 minutes
} else {
    echo 'Data retrieved from cache!' . PHP_EOL;
    var_dump($cachedData);
}

// set your custom configuration options (below are default ones)
Kminek_Cache::configure(array(
    'engine' => Kminek_Cache::ENGINE_SERIALIZE, // or Kminek_Cache::ENGINE_JSON or Kminek_Cache::ENGINE_VAR_EXPORT
    'dir' => sys_get_temp_dir(), // where to store cache files
    'prefix' => 'kminek_cache',
    'separator' => '_',
    'extension' => '.cache',
    'ttl' => 60 * 60, // default ttl in seconds (1 hour)
));

// then use cache as you would normally do
$cachedData = cache_get('cachedData');
...