PHP code example of pinkcrab / wp-psr16-cache

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

    

pinkcrab / wp-psr16-cache example snippets


$wp_uploads = wp_upload_dir();

$cache = new File_Cache( $wp_uploads['basedir'] . '/my-cache', '.cache' );

$cache->set( 'my_key', array( 'some', 'data' ) );

// Creates  /public/wp-content/uploads/my-cache/my_key.cache

/**
 * Creates the cache directory.
 */
function called_on_activation() {
    new File_Cache( $wp_uploads['basedir'] . '/my-cache', '.cache' );
}

/**
 * Removes every cache entry in the directory.
 * Note: clear() removes the files inside the directory; the directory itself is left in place.
 */
function called_on_uninstall() {
    ( new File_Cache( $wp_uploads['basedir'] . '/my-cache', '.cache' ) )->clear();
}

$cache = new Transient_Cache( 'my_cache' );

$cache->set( 'my_key', array( 'some', 'data' ) );

// The value can be read back via either:
$value = get_transient( 'my_cache_my_key' );
( new Transient_Cache( 'my_cache' ) )->get( 'my_key' );


// Or create an instance with no group prefix:
$cache = new Transient_Cache();
$cache->set( 'my_other_key', array( 'some', 'data' ) );
$value = get_transient( 'my_other_key' );