-
Notifications
You must be signed in to change notification settings - Fork 0
/
object-cache-test.php
106 lines (66 loc) · 2.99 KB
/
object-cache-test.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
<?php
function _deprecated_function($a, $b, $c) {}
$blog_id = 1;
$table_prefix = 'wp_';
define( 'DB_NAME', 'db_name' );
define( 'DAY_IN_SECONDS', 600 );
function bool_to_str( $val ) {
return ( $val ? 'true' : 'false' ) . "\n";
}
require_once 'object-cache.php';
// test wp_cache_init();
wp_cache_init();
global $wp_object_cache;
echo "Cache object exist: " . bool_to_str( $wp_object_cache instanceof WP_Object_Cache );
wp_cache_flush();
// test wp_cache_incr and wp_cache_get
wp_cache_incr('integer', 1, 'test-group');
wp_cache_incr('integer', 3, 'test-group');
$r = wp_cache_get('integer', 'test-group');
$rf = wp_cache_get('integer', 'test-group', true);
echo "wp_cache_incr force: " . bool_to_str( $r == $rf );
echo "wp_cache_incr: " . bool_to_str( $r == 4 );
// test wp_cache_decr
wp_cache_decr('integer', 1, 'test-group');
wp_cache_decr('integer', 3, 'test-group');
wp_cache_decr('integer', 1, 'test-group');
$r = wp_cache_get('integer', 'test-group');
$rf = wp_cache_get('integer', 'test-group', true);
echo "wp_cache_decr force: " . bool_to_str( $r == $rf );
echo "wp_cache_decr: " . bool_to_str( $r == -1 );
// test wp_cache_add
$true = wp_cache_add('key', 'value', 'test-group');
$false = wp_cache_add('integer', 'value', 'test-group');
echo "wp_cache_add: " . bool_to_str( $true === true );
echo "wp_cache_add exist: " . bool_to_str( $false === false );
$r = wp_cache_get('key', 'test-group');
$rf = wp_cache_get('key', 'test-group', true);
echo "wp_cache_add > wp_cache_get force: " . bool_to_str( $r == $rf );
echo "wp_cache_add > wp_cache_get: " . bool_to_str( $r == 'value' );
$r = wp_cache_get('integer', 'test-group');
$rf = wp_cache_get('integer', 'test-group', true);
echo "wp_cache_add exist > wp_cache_get force: " . bool_to_str( $r == $rf );
echo "wp_cache_add exist > wp_cache_get: " . bool_to_str( $r == -1 );
// test wp_cache_delete
wp_cache_delete('key', 'test-group');
wp_cache_delete('integer', 'test-group');
$false = wp_cache_get('key', 'test-group');
$falsef = wp_cache_get('integer', 'test-group', true);
echo "wp_cache_delete > wp_cache_get force:" . bool_to_str( $falsef === $false );
echo "wp_cache_delete > wp_cache_get: " . bool_to_str( $false === false );
// test wp_cache_replace
$false = wp_cache_replace('key', 'value', 'test-group');
wp_cache_set('key', 'value', 'test-group');
$true = wp_cache_replace('key', 'value', 'test-group');
echo "wp_cache_replace: " . bool_to_str( $true === true );
echo "wp_cache_replace no exist: " . bool_to_str( $false == false );
$r = wp_cache_get('key', 'test-group');
$rf = wp_cache_get('key', 'test-group', true);
echo "wp_cache_replace > wp_cache_get force: " . bool_to_str( $r == $rf );
echo "wp_cache_replace > wp_cache_get: " . bool_to_str( $r == 'value' );
// test wp_cache_set
wp_cache_set('a', 'b', 'test-group');
$r = wp_cache_get('a', 'test-group');
$rf = wp_cache_get('a', 'test-group', true);
echo "wp_cache_set > wp_cache_get force: " . bool_to_str( $r == $rf );
echo "wp_cache_set > wp_cache_get: " . bool_to_str( $r =='b');