PHP code example of padosoft / laravel-super-cache

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

    

padosoft / laravel-super-cache example snippets


use SuperCache; // alias registered by the package

// Store an item in cache (optional TTL in seconds, optional Redis connection name)
SuperCache::put('user:1', $user, 3600);

// Store an item in cache with tags
// Extra optional params: $ttl, $connection_name, $serialize (default true),
// $disableCompression (default false, useful on Redis clusters using OPT_COMPRESSION)
SuperCache::putWithTags('product:1', $product, ['products', 'featured'], 3600);

// Remember: read-through cache with tags
$product = SuperCache::rememberWithTags('product:1', ['products'], function () {
    return Product::find(1);
}, 3600);

// Retrieve an item from cache
$product = SuperCache::get('product:1');

// Check if a key exists
$exists = SuperCache::has('user:1');

// Get the TTL of a key (in seconds)
$ttl = SuperCache::getTTLKey('user:1');

// Increment / decrement counters
SuperCache::increment('views:product:1');
SuperCache::decrement('stock:product:1', 5);

// Remove a single key (and, in advanced mode, its tag references)
SuperCache::forget('user:1');

// Invalidate every key associated with one or more tags
SuperCache::flushByTags(['products', 'featured']);

// Introspection helpers
$tagsOfKey = SuperCache::getTagsOfKey('product:1');
$keysOfTag = SuperCache::getKeysOfTag('products');

// Get all keys matching one or more patterns
$keys = SuperCache::getKeys(['product:*']);

// Acquire / release a short-lived optimistic lock
if (SuperCache::lock('job:import', null, 10)) {
    try {
        // critical section
    } finally {
        SuperCache::unLock('job:import');
    }
}

// Flush the whole SuperCache keyspace on a given connection
SuperCache::flush();
bash 
php artisan vendor:publish --provider="Padosoft\SuperCache\SuperCacheServiceProvider"

php artisan supercache:listener
    [--connection_name=<redis connection>]
    [--namespace_id=<id>]
    [--checkEvent=1]
    [--host=<cluster node host>]
    [--port=<cluster node port>]
bash
php artisan supercache:clean-orphans [--connection_name=<redis connection>]
bash
php artisan supercache:clean-orphans [--connection_name=<redis connection>]