PHP code example of mazz / global-static-cache-manager

1. Go to this page and download the library: Download mazz/global-static-cache-manager 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/ */

    

mazz / global-static-cache-manager example snippets


// Receive the Cache with the currency_cache
$currencyCache = StaticCacheContainer::getInstance()->get('currency_cache');
   
// Fill the cache one by one
$currencyCache->set(1, 'currency1');
$currencyCache->set(2, 'currency2');
$currencyCache->set(3, 'currency3');
    
// It is also possible to fill multiple at once
$currencyCache->setMultiple([
    4 => 'currency4',
    5 => 'currency5',
]);

// Get the currency which is saved on index 4
$currency = StaticCacheContainer::getInstance()->get('currency_cache')->get(4);
   
// it is also possible to set a default value
$currency = StaticCacheContainer::getInstance()->get('currency_cache')->get(42, 'defaultCurrency');
   
// or load multiple keys at once
$currency = StaticCacheContainer::getInstance()->get('currency_cache')->get([1,2,3);


// Returns true if cache with the key my_cache_key exists, false otherwise
if(!StaticCacheContainer::getInstance()->has('my_cache_key')) {
    // you may want to fill the cache here
}