dev-master
9999999-devCache method, function or closure results.
MIT
The Development Requires
by Titas Gailius
cache closure
1.0
1.0.0.0Cache method, function or closure results.
MIT
The Development Requires
by Titas Gailius
cache closure
Wallogit.com
2017 © Pedro Peláez
Cache method, function or closure results.
A simple PHP cache mechanism for storing method, function or closure results.\ It calculates result of the closure once and returns it on subsequent calls., (*1)
<?php
function somethingSlow()
{
return once(function () {
// Code...
});
}
$ composer require titasgailius/closure-cache
{
"require": {
"titasgailius/closure-cache": "~1.00"
}
}
<?php
class SomeClass
{
public static function think()
{
sleep(10);
return 'It takes some time to process this.';
}
}
/**
* 10 seconds to process it.
*/
SomeClass::think();
/**
* Another 10 seconds to process it
* which makes it 20 seconds in total.
*/
SomeClass::think();
<?php
class SomeClass
{
public static function think()
{
return once(function () {
sleep(10);
return 'It takes some time to process this.';
});
}
}
/**
* 10 seconds to process
*/
SomeClass::think();
/**
* ClosureCache detects that this was already
* processed and returns it from the cache.
*/
SomeClass::think();
<?php
class SomeClass
{
public static function think($message)
{
return once(function () use ($message) {
sleep(10);
return $message;
});
}
}
/**
* 10 seconds to process
*/
SomeClass::think('foo');
/**
* Another 10 seconds to process it because
* different parameters were passed.
*/
SomeClass::think('bar');
Cache method, function or closure results.
MIT
cache closure
Cache method, function or closure results.
MIT
cache closure