Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class KrakenApiCache{
- private static $cache = array();
- /**
- * Cache a variabele for X time
- *
- * @param string $key
- * @param mixed $value
- * @param float $timeout seconds (0.1, 0.5, 1, 10)
- */
- public static function set($key, $value, $timeout = 1){
- self::$cache[$key] = array(
- 'value' => $value,
- 'timeout' => $timeout,
- 'microtime' => microtime(true)
- );
- }
- /**
- * Get a variable from cache
- * Or return false if ttl is passed
- *
- * @param string $key
- */
- public static function get($key){
- if (isset(self::$cache[$key])){
- $timeout = self::$cache[$key]['timeout'];
- if (abs(microtime(true) - self::$cache[$key]['microtime']) <= self::$cache[$key]['timeout']){
- return self::$cache[$key]['value'];
- }
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment