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

Options_Cache   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 39
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A get() 0 5 1
A put() 0 5 1
A flush_all() 0 9 2
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
}