PocketMine-MP  1.4 - API 1.10.0
 All Classes Namespaces Functions Variables Pages
Cache.php
1 <?php
2 
3 /*
4  *
5  * ____ _ _ __ __ _ __ __ ____
6  * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
7  * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
8  * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
9  * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
10  *
11  * This program is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License as published by
13  * the Free Software Foundation, either version 3 of the License, or
14  * (at your option) any later version.
15  *
16  * @author PocketMine Team
17  * @link http://www.pocketmine.net/
18  *
19  *
20 */
21 
22 namespace pocketmine\utils;
23 
24 
25 class Cache{
26  public static $cached = [];
27 
35  public static function add($identifier, $blob, $minTTL = 30){
36  self::$cached[$identifier] = [$blob, microtime(true) + $minTTL, $minTTL];
37  }
38 
46  public static function get($identifier){
47  if(isset(self::$cached[$identifier])){
48  self::$cached[$identifier][1] = microtime(true) + self::$cached[$identifier][2];
49 
50  return self::$cached[$identifier][0];
51  }
52 
53  return false;
54  }
55 
61  public static function exists($identifier){
62  return isset(self::$cached[$identifier]);
63  }
64 
68  public static function remove($identifier){
69  unset(self::$cached[$identifier]);
70  }
71 
75  public static function cleanup(){
76  $time = microtime(true);
77  foreach(self::$cached as $index => $data){
78  if($data[1] < $time){
79  unset(self::$cached[$index]);
80  }
81  }
82  }
83 
84 }
static cleanup()
Definition: Cache.php:75
static add($identifier, $blob, $minTTL=30)
Definition: Cache.php:35
static exists($identifier)
Definition: Cache.php:61