PHP code example of fmihel / php-cache

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

    

fmihel / php-cache example snippets




ihel\cache\Cache;
use fmihel\cache\drivers\FileCacheDriver;

const KEY_1 = 'key_1';

class MyClass{

    static function strong($count1 = 10000,$count2 = 10000){
        sleep(1);  
        $out = 0;
        for($i=0;$i<$count1;$i++){
            for($j=0;$j<$count2;$j++){
                $out++;
            };
        };
        return $out;
    }

    static function cached_strong($count1 = 10000,$count2 = 10000){
        global $cache;
        return $cache->get(KEY_1,func_get_args(),function() use($count1,$count2){
            
            return self::strong($count1,$count2);

        });
    }
};


$cache = new Cache(new FileCacheDriver(/*path*/));// default story cache to $_SERVER['PWD'].'/cache';

$get = MyClass::cached_strong(1000000,100000);