fmihel / php-cache
php,cache
v3.0.0
2024-10-28 06:44 UTC
Requires
- fmihel/php-lib: ^6.0
Requires (Dev)
- fmihel/console-log: ^1.4
- fmihel/php-base: ^1.2
- fmihel/php-config: ^0.1.2
- phpunit/phpunit: ^8.0
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); ?>