PHP code example of micropackage / cache

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

    

micropackage / cache example snippets


use Micropackage\Cache\Driver\ObjectCache;

$object_cache = new ObjectCache( $group = 'my_group', $expiration = DAY_IN_SECONDS );
$object_cache->set_key( 'cache_key' );

use Micropackage\Cache\Driver\Transient;

$transient_cache = new Transient( $expiration = DAY_IN_SECONDS );
$transient_cache->set_key( 'cache_key' );

use Micropackage\Cache\Cache;
use Micropackage\Cache\Driver\ObjectCache;

$driver = new ObjectCache( $group = 'my_group', $expiration = DAY_IN_SECONDS );
$cache  = new Cache( $driver, $cache_key = 'extremaly_important_thing' );

$the_thing = $cache->collect( function() {
	return 'The value was not set apparently';
} );

$some_var = 'I am awesome!';

$the_thing = $cache->collect( function() use ( $some_var ) {
	return $some_var;
} );
set( (mixed) $value )
add( (mixed) $value )
set( (mixed) $value )
add( (mixed) $value )