NetworkCache.php
2.45 KB
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
<?php
namespace AIOSEO\Plugin\Common\Utils;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Handles our network cache.
*
* @since 4.2.5
*/
class NetworkCache extends Cache {
/**
* Returns the cache value for a key if it exists and is not expired.
*
* @since 4.2.5
*
* @param string $key The cache key name. Use a '%' for a like query.
* @return mixed The value or null if the cache does not exist.
*/
public function get( $key ) {
if ( ! is_multisite() ) {
return parent::get( $key );
}
aioseo()->helpers->switchToBlog( aioseo()->helpers->getNetworkId() );
$value = parent::get( $key );
aioseo()->helpers->restoreCurrentBlog();
return $value;
}
/**
* Updates the given cache or creates it if it doesn't exist.
*
* @since 4.2.5
*
* @param string $key The cache key name.
* @param mixed $value The value.
* @param int $expiration The expiration time in seconds. Defaults to 24 hours. 0 to no expiration.
* @return void
*/
public function update( $key, $value, $expiration = DAY_IN_SECONDS ) {
if ( ! is_multisite() ) {
parent::update( $key, $value, $expiration );
return;
}
aioseo()->helpers->switchToBlog( aioseo()->helpers->getNetworkId() );
parent::update( $key, $value, $expiration );
aioseo()->helpers->restoreCurrentBlog();
}
/**
* Deletes the given cache key.
*
* @since 4.2.5
*
* @param string $key The cache key.
* @return void
*/
public function delete( $key ) {
if ( ! is_multisite() ) {
parent::delete( $key );
return;
}
aioseo()->helpers->switchToBlog( aioseo()->helpers->getNetworkId() );
parent::delete( $key );
aioseo()->helpers->restoreCurrentBlog();
}
/**
* Clears all of our cache.
*
* @since 4.2.5
*
* @return void
*/
public function clear() {
if ( ! is_multisite() ) {
parent::clear();
return;
}
aioseo()->helpers->switchToBlog( aioseo()->helpers->getNetworkId() );
parent::clear();
aioseo()->helpers->restoreCurrentBlog();
}
/**
* Clears all of our cache under a certain prefix.
*
* @since 4.2.5
*
* @param string $prefix A prefix to clear or empty to clear everything.
* @return void
*/
public function clearPrefix( $prefix ) {
if ( ! is_multisite() ) {
parent::clearPrefix( $prefix );
return;
}
aioseo()->helpers->switchToBlog( aioseo()->helpers->getNetworkId() );
parent::clearPrefix( $prefix );
aioseo()->helpers->restoreCurrentBlog();
}
}