PHP code example of hms5232 / laravel-twin-cache

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

    

hms5232 / laravel-twin-cache example snippets


'stores' => [
    // other store config here

    'twin' => [
        'driver' => 'twin',
        'older' => env('TWIN_CACHE_OLDER', 'redis'),  // First/preferred cache
        'younger' => env('TWIN_CACHE_YOUNGER', 'database'),  // Second/backup cache
        'sync_ttl' => env('TWIN_CACHE_TTL'),  // TTL for younger synced to older. Default is null => forever
    ],
],

Cache::put('foo', 'bar');
// change "put" to "putTwin"
Cache::putTwin('foo', 'bar');

// only select older cache
Cache::get('foo');

// This will select older cache first
// If no result, select younger, else return result
// 1. If exists in younger, insert into older cache and return
// 2. If it doesn't exist, return default value
Cache::getTwin('foo', 'bar');