PHP code example of icanboogie / storage

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

    

icanboogie / storage example snippets




use ICanBoogie\Storage\RunTimeStorage;

$storage = new RunTimeStorage;
$storage->exists('icanboogie');     // false
$storage->retrieve('icanboogie');   // null
$storage->store('icanboogie', "Yes Sir, I Can Boogie");
$storage->retrieve('icanboogie');   // "Yes Sir, I Can Boogie"
$storage->eliminate('icanboogie');
$storage->exists('icanboogie');     // false
$storage->retrieve('icanboogie');   // null



use ICanBoogie\Storage\RunTimeStorage;

$storage = new RunTimeStorage;
$storage->store('icanboogie', "Yes Sir, I Can Boogie", $ttl = 3);
$storage->retrieve('icanboogie');   // "Yes Sir, I Can Boogie"
sleep(4);
$storage->exists('icanboogie');     // false
$storage->retrieve('icanboogie');   // null



use ICanBoogie\Storage\RunTimeStorage;

$storage = new RunTimeStorage;
isset($storage['icanboogie']);     // false
$storage['icanboogie'];            // null
$storage['icanboogie'] = "Yes Sir, I Can Boogie";
$storage['icanboogie'];            // "Yes Sir, I Can Boogie"
unset($storage['icanboogie']);
isset($storage['icanboogie']);     // false
$storage['icanboogie'];            // null



$storage['one'] = 1;
$storage['two'] = 2;
$storage['three'] = 3;

foreach ($storage as $key)
{
    echo "defined: $key\n";
}



use ICanBoogie\Storage\StorageCollection;
use ICanBoogie\Storage\RunTimeStorage;
use ICanBoogie\Storage\APCStorage;
use ICanBoogie\Storage\RedisStorage;
use ICanBoogie\Storage\FileStorage;

$storage = new StorageCollection([

    new RunTimeStorage,
    new APCStorage('my-prefix'),
    new RedisStorage($redis_client, 'my-prefix'),
    new FileStorage('/path/to/directory')

]);