fmihel/php-cache

v3.0.0 2024-10-28 06:44 UTC

This package is auto-updated.

Last update: 2024-11-28 07:00:26 UTC


README

simple cache for php functions result

Install

composer require fmihel/php-cache

Example

<?php

require_once __DIR__ . '/vendor/autoload.php';
use fmihel\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);


?>

class Cache