Completed
Pull Request — develop (#1328)
by Naveen
03:00
created

Options_Cache::put()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 2
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Wordlift\Vocabulary\Cache;
4
5
class Options_Cache implements Cache {
6
7
	private $namespace;
8
9
	/**
10
	 * Options_Cache constructor.
11
	 *
12
	 * @param $namespace
13
	 */
14
	public function __construct( $namespace ) {
15
		$this->namespace = $namespace;
16
	}
17
18
19
	public function get( $cache_key ) {
20
21
		return get_option( $this->namespace . '__' . $cache_key, false );
22
23
	}
24
25
26
	public function put( $cache_key, $value ) {
27
28
		return update_option( $this->namespace . '__' . $cache_key, $value );
29
30
	}
31
32
	public function flush_all() {
33
		if ( $this->namespace !== '' ) {
34
			global $wpdb;
35
			$options_table_name = $wpdb->options;
36
			$namespace_esc = $wpdb->esc_like( $this->namespace ) . '__%';
37
			$sql         = $wpdb->prepare( "DELETE FROM $options_table_name WHERE option_name LIKE %s", $namespace_esc );
38
			$wpdb->query( $sql );
39
		}
40
	}
41
42
43
}