Last active
June 12, 2018 08:21
-
-
Save ViliamKopecky/f4bf375d57f7c528f73f959e0a5adf72 to your computer and use it in GitHub Desktop.
PHP cached calling functions proxy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
# Usage | |
# just prefix old function call with `Memoize::` | |
someFunction("foo", 123); | |
Memoize::someFunction("foo", 123); | |
*/ | |
class Memoize | |
{ | |
public static $enabled = true; | |
private static $cache = []; | |
public static function __callStatic($name, $arguments) | |
{ | |
$key = serialize([$name, $arguments]); | |
if (isset(self::$cache[$key])) { | |
return self::$cache[$key]; | |
} | |
return self::$cache[$key] = call_user_func_array($name, $arguments); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment