-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdriver.php
124 lines (107 loc) · 2.66 KB
/
driver.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?php
namespace Cache\Driver;
// load dependencies
require_once(__DIR__ . DS . 'vendor' . DS . 'autoload.php');
use Cache\Driver;
use MemCachier\MemcacheSASL;
class MemCachier extends Driver {
// store for the memache connection
protected $connection = null;
/**
* Initialize memcachier connection.
*/
public function __construct($params = array()) {
$this->connection = new MemcacheSASL();
$defaults = array(
'prefix' => null,
);
$this->options = array_merge($defaults, (array)$params);
$servers = explode(",", getenv("MEMCACHIER_SERVERS"));
foreach ($servers as $server) {
$parts = explode(":", $server);
$this->connection->addServer($parts[0], $parts[1]);
}
// Setup authentication
$this->connection->setSaslAuthData(getenv("MEMCACHIER_USERNAME")
,getenv("MEMCACHIER_PASSWORD") );
}
/**
* Write an item to the cache for a given number of minutes.
*
* <code>
* // Put an item in the cache for 15 minutes
* Cache::set('value', 'my value', 15);
* </code>
*
* @param string $key
* @param mixed $value
* @param int $minutes
* @return void
*/
public function set($key, $value, $minutes = null) {
return $this->connection->set($this->key($key), $this->value($value, $minutes), $this->expiration($minutes));
}
/**
* Returns the full keyname
* including the prefix (if set)
*
* @param string $key
* @return string
*/
public function key($key) {
return $this->options['prefix'] . $key;
}
/**
* Retrieve the CacheValue object from the cache.
*
* @param string $key
* @return object CacheValue
*/
public function retrieve($key) {
return $this->connection->get($this->key($key));
}
/**
* Remove an item from the cache
*
* @param string $key
* @return boolean
*/
public function remove($key) {
return $this->connection->delete($this->key($key));
}
/**
* Checks when an item in the cache expires
*
* @param string $key
* @return int
*/
public function expires($key) {
return parent::expires($this->key($key));
}
/**
* Checks if an item in the cache is expired
*
* @param string $key
* @return int
*/
public function expired($key) {
return parent::expired($this->key($key));
}
/**
* Checks when the cache has been created
*
* @param string $key
* @return int
*/
public function created($key) {
return parent::created($this->key($key));
}
/**
* Flush the entire cache directory
*
* @return boolean
*/
public function flush() {
return $this->connection->flush();
}
}