PluginProbe
UpStream: a Project Management Plugin for WordPress / 1.39.0
UpStream: a Project Management Plugin for WordPress v1.39.0
trunk 1.39.0 1.39.1 1.39.2 1.39.3 2.0.7 2.1.0
upstream / includes / class-up-cache.php

class-up-cache.php in UpStream: a Project Management Plugin for WordPress 1.39.0, at includes/class-up-cache.php

83 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 // Exit if accessed directly
3 if ( ! defined('ABSPATH')) {
4 exit;
5 }
6
7 class Upstream_Cache
8 {
9 protected static $instance;
10
11 protected $cache = [];
12
13 public function set($key, $value)
14 {
15 $this->cache[$key] = $value;
16 }
17
18 public function get($key)
19 {
20 if (isset($this->cache[$key])) {
21 return $this->cache[$key];
22 }
23
24 return false;
25 }
26
27 public function reset()
28 {
29 $this->cache = [];
30 }
31
32 public static function get_instance()
33 {
34 if (empty(static::$instance)) {
35 $instance = new self;
36 static::$instance = $instance;
37 }
38
39 return static::$instance;
40 }
41 }
42
43 function upstream_cache_get_metadata()
44 {
45 $str = "upstream_cache_get_metadata";
46 $args = func_get_args();
47
48 for ($i = 0; $i < func_num_args(); $i++) {
49 $str .= $args[$i];
50 }
51
52 $cache = Upstream_Cache::get_instance();
53 $res = $cache->get($str);
54
55 if ($res !== false) {
56 return $res;
57 }
58
59 $cache->set($str, $res);
60
61 return call_user_func_array('get_metadata', $args);
62 }
63
64 function upstream_cache_get_post_meta()
65 {
66 $str = "upstream_cache_get_post_meta";
67 $args = func_get_args();
68
69 for ($i = 0; $i < func_num_args(); $i++) {
70 $str .= $args[$i];
71 }
72
73 $cache = Upstream_Cache::get_instance();
74 $res = $cache->get($str);
75
76 if ($res !== false) {
77 return $res;
78 }
79
80 $cache->set($str, $res);
81
82 return call_user_func_array('get_post_meta', $args);
83 }