Completed
Push — master ( 94ddbb...e5219e )
by Jean-Christophe
04:25
created

SessionCache   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 57.14%

Importance

Changes 0
Metric Value
wmc 9
eloc 14
dl 0
loc 37
ccs 12
cts 21
cp 0.5714
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A remove() 0 2 1
A fetch() 0 2 1
A clear() 0 4 3
A getEntryKey() 0 2 1
A exists() 0 2 1
A __construct() 0 3 1
A store() 0 3 1
1
<?php
2
3
namespace Ubiquity\cache\objects;
4
5
use Ubiquity\utils\http\USession;
6
use Ubiquity\utils\base\UString;
7
8
class SessionCache {
9
	private $session;
10
	const ENTRY_KEY="_session_cache";
11
	
12 3
	public function __construct(){
13 3
		$this->session=new USession();
14 3
		$this->session->start();
15 3
	}
16
17
	public function fetch($key) {
18
		return $this->session->get($this->getEntryKey($key));
19
	}
20
21
	public function clear() {
22
		foreach($_SESSION as $k=>$notUsed){
23
			if(UString::startswith($k, self::ENTRY_KEY.".")){
24
				unset ( $_SESSION [$k] );
25
			}
26
		}
27
	}
28
29 3
	public function exists($key) {
30 3
		return $this->session->exists($this->getEntryKey($key));
31
	}
32
33 3
	public function getEntryKey($key) {
34 3
		return self::ENTRY_KEY.'.'.$key;
35
	}
36
	
37 2
	public function store($key, $object) {
38 2
		$key=$this->getEntryKey($key);
39 2
		$this->session->set($key, $object);
40 2
	}
41
42
43
	public function remove($key) {
44
		$this->session->delete($this->getEntryKey($key));
45
	}
46
}
47
48