PHP code example of flatphp / cache

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

    

flatphp / cache example snippets


composer 

use Flatphp\Memstore\Conn;
use Flatphp\Cache\Cache;

Conn::init(array(
    'memcache' => ['host' => '127.0.0.1', 'port' => 11211]
));

Cache::init(array(
    'expiration' => 3600, // the default expiration, 0 forever[default]
    'storage' => 'memcache',
));

// -------- OR --------------------

Cache::init(array(
    'expiration' => 3600, // the default expiration, 0 forever[default]
    'storage' => array(
        'driver' => 'redis',
	'host' => 'localhost',
	'port' => 6379
    )
));


use Flatphp\Cache\Cache;

Cache::set('test', 1, 60);
echo Cache::get('test');
Cache::delete('test');
Cache::flush();

Cache::increment('test', 2);
Cache::decrement('test', 2);

Cache::getData('test', function(){
    return 'hello';
});