-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdebug_cache.php
156 lines (114 loc) · 4.38 KB
/
debug_cache.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<?php
namespace aw2\debug_cache;
\aw2_library::add_service('debug_cache.set_access_post_type','Set the Debug Cache',['namespace'=>__NAMESPACE__]);
function set_access_post_type($atts,$content=null,$shortcode=null){
if(\aw2_library::pre_actions('all',$atts,$content)==false)return;
extract(\aw2_library::shortcode_atts( array(
'post_type'=>null,
'fields'=>array()
), $atts) );
if(!$post_type)return 'Invalid Post Type';
if(empty($fields))return 'Missing fields data';
$redis = \aw2_library::redis_connect(REDIS_DATABASE_DEBUG_CACHE);
$key = 'post_type:'.$post_type;
foreach($fields as $k=>$value){
$redis->hset($key, $k,$value);
}
$redis->hIncrBy($key, 'count', 1);
return;
}
\aw2_library::add_service('debug_cache.set_access_module','Set the Debug Cache',['namespace'=>__NAMESPACE__]);
function set_access_module($atts,$content=null,$shortcode=null){
if(\aw2_library::pre_actions('all',$atts,$content)==false)return;
extract(\aw2_library::shortcode_atts( array(
'post_type'=>null,
'module'=>null,
'fields'=>array()
), $atts) );
if(!$post_type)return 'Invalid Post Type';
if(!$module)return 'Missing Module Slug';
if(empty($fields))return 'Missing fields data';
$redis = \aw2_library::redis_connect(REDIS_DATABASE_DEBUG_CACHE);
$key = 'module:'.$post_type.'#'.$module;
foreach($fields as $k=>$value){
$redis->hset($key, $k,$value);
}
$redis->hIncrBy($key, 'count', 1);
return;
}
\aw2_library::add_service('debug_cache.set_access_app','Set the Debug Cache',['namespace'=>__NAMESPACE__]);
function set_access_app($atts,$content=null,$shortcode=null){
if(\aw2_library::pre_actions('all',$atts,$content)==false)return;
extract(\aw2_library::shortcode_atts( array(
'app'=>null,
'fields'=>array()
), $atts) );
if(!$app)return 'App slug is missing';
if(empty($fields))return 'Missing fields data';
$redis = \aw2_library::redis_connect(REDIS_DATABASE_DEBUG_CACHE);
$key = 'app:'.$app;
foreach($fields as $k=>$value){
$redis->hset($key, $k,$value);
}
$redis->hIncrBy($key, 'cnt', 1);
if(defined('SET_ENV_CACHE') && SET_ENV_CACHE)$redis->hIncrBy($key, 'cache_cnt', 1);
return;
}
\aw2_library::add_service('debug_cache.getkeys','Get the Debug Cache',['namespace'=>__NAMESPACE__]);
function getkeys($atts,$content=null,$shortcode=null){
if(\aw2_library::pre_actions('all',$atts,$content)==false)return;
extract(\aw2_library::shortcode_atts( array(
'main'=>null,
'field'=>null
), $atts) );
if(!$main)return 'Main must be set';
//Connect to Redis and store the data
$redis = \aw2_library::redis_connect(REDIS_DATABASE_DEBUG_CACHE);
$return_value = $redis->keys($main);
$return_value=\aw2_library::post_actions('all',$return_value,$atts);
return $return_value;
}
\aw2_library::add_service('debug_cache.hget','Get the Debug Cache',['namespace'=>__NAMESPACE__]);
function hget($atts,$content=null,$shortcode=null){
if(\aw2_library::pre_actions('all',$atts,$content)==false)return;
extract(\aw2_library::shortcode_atts( array(
'main'=>null,
'field'=>null
), $atts) );
if(!$main)return 'Main must be set';
//if(!$field)return 'Invalid field';
if($prefix)$main=$prefix . $main;
//Connect to Redis and store the data
$redis = \aw2_library::redis_connect(REDIS_DATABASE_DEBUG_CACHE);
$return_value='';
if($redis->exists($main)){
if($field)
$return_value = $redis->hget($main,$field);
else
$return_value = $redis->hGetAll($main);
}
$return_value=\aw2_library::post_actions('all',$return_value,$atts);
return $return_value;
}
\aw2_library::add_service('debug_cache.flush','Flush the Debug Cache',['namespace'=>__NAMESPACE__]);
function flush($atts,$content=null,$shortcode){
if(\aw2_library::pre_actions('all',$atts,$content,$shortcode)==false)return;
//Connect to Redis and store the data
$redis = \aw2_library::redis_connect(REDIS_DATABASE_DEBUG_CACHE);
$redis->flushdb() ;
}
function exists($atts,$content=null,$shortcode=null){
if(\aw2_library::pre_actions('all',$atts,$content)==false)return;
extract(\aw2_library::shortcode_atts( array(
'main'=>null,
'prefix'=>'',
), $atts) );
if(!$main)return 'Main must be set';
if($prefix)$main=$prefix . $main;
//Connect to Redis and store the data
$redis = \aw2_library::redis_connect(REDIS_DATABASE_DEBUG_CACHE);
$return_value=false;
if($redis->exists($main))$return_value = true;
$return_value=\aw2_library::post_actions('all',$return_value,$atts);
return $return_value;
}