PHP code example of rockschtar / wordpress-object-storage

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

    

rockschtar / wordpress-object-storage example snippets


// without expiration time: stored until deleted
rsos_set_object('my-key', 'my-value');

// with expiration time in seconds
rsos_set_object('my-key', 'my-value', DAY_IN_SECONDS);

$value = rsos_get_object('my-key');

rsos_delete_object('my-key');

use Rockschtar\WordPress\ObjectStorage\ObjectStorage;

$storage = new ObjectStorage();

$storage->set('my-key', ['foo' => 'bar'], HOUR_IN_SECONDS);
$storage->get('my-key');                // false|mixed
$storage->delete('my-key');             // bool

$storage->expires('my-key');            // expiration as unix timestamp, null if none
$storage->expiresAsDateTime('my-key');  // expiration as DateTime (site timezone), null if none
$storage->getItem('my-key');            // ObjectStorageItem with key, value and expiration

$storage->deleteExpired();              // delete all expired objects (what the cron job runs)
$storage->clear();                      // delete ALL stored objects, expired or not