Hoa central
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
Hoa\Cache\Backend\Memcache Class Reference
Inheritance diagram for Hoa\Cache\Backend\Memcache:

Public Member Functions

 __construct (Array $parameters=[])
 
 store ($data)
 
 load ()
 
 clean ($lifetime=Cache::CLEAN_ALL)
 
 remove ()
 
 __destruct ()
 
- Public Member Functions inherited from Hoa\Cache\Backend\Backend
 store ($data)
 
 load ()
 
 clean ($lifetime=Cache::CLEAN_EXPIRED)
 
 remove ()
 
- Public Member Functions inherited from Hoa\Cache\Cache
 __construct (Array $parameters=[])
 
 getParameters ()
 
 ksort (Array &$array)
 

Protected Member Functions

 setMemcache ()
 
- Protected Member Functions inherited from Hoa\Cache\Cache
 makeId ($id=null)
 
 setId ($id)
 
 getId ()
 
 getIdMd5 ()
 
 removeId ()
 

Protected Attributes

 $_memcache = null
 

Additional Inherited Members

- Public Attributes inherited from Hoa\Cache\Cache
const CLEAN_ALL = -1
 
const CLEAN_EXPIRED = 0
 
const CLEAN_USER = 1
 
- Static Protected Attributes inherited from Hoa\Cache\Cache
static $_id = []
 

Detailed Description

Class .

Memcache backend manager. Memcache is PECL extension, so it's not installed in PHP. Take care that Memcache module is loaded.

Definition at line 51 of file Memcache.php.

Constructor & Destructor Documentation

Hoa\Cache\Backend\Memcache::__construct ( Array  $parameters = [])

Check if Memcache is loaded and prepare variables.

Parameters
array$parametersParameters.
Returns
void
Exceptions

Definition at line 69 of file Memcache.php.

70  {
71  if (!extension_loaded('memcache')) {
72  throw new Cache\Exception(
73  'Memcache module extension is not loaded on server.',
74  0
75  );
76  }
77 
78  parent::__construct($parameters);
79 
80  return;
81  }
Hoa\Cache\Backend\Memcache::__destruct ( )

Close connection to Memcache.

Returns
void

Definition at line 206 of file Memcache.php.

207  {
208  if ($this->_memcache !== null) {
209  $this->_memcache->close();
210  unset($this->_memcache);
211  }
212 
213  return;
214  }

Member Function Documentation

Hoa\Cache\Backend\Memcache::clean (   $lifetime = Cache::CLEAN_ALL)

Flush all existing items on Memcache server. Note : only ::CLEAN_ALL is supported by Memcache.

Parameters
int$lifetimeSpecific lifetime.
Returns
void
Exceptions

Definition at line 144 of file Memcache.php.

145  {
146  $this->setMemcache();
147 
148  if ($lifetime != Cache::CLEAN_ALL) {
149  throw new Cache\Exception(
150  'Only \Hoa\Cache::CLEAN_ALL constant is supported by ' .
151  'Memcache backend.',
152  1
153  );
154  }
155 
156  if (false === @$this->_memcache->flush()) {
157  throw new Cache\Exception(
158  'Flush all existing items on Memcache server %s failed.',
159  2,
160  $this->_parameters->getParameter('memcache.database.host')
161  );
162  }
163 
164  return;
165  }
const CLEAN_ALL
Definition: Cache.php:55

Here is the call graph for this function:

Here is the caller graph for this function:

Hoa\Cache\Backend\Memcache::load ( )

Load a Memcache items.

Returns
mixed

Definition at line 122 of file Memcache.php.

123  {
124  $this->setMemcache();
125  $this->clean();
126 
127  $content = $this->_memcache->get($this->getIdMd5());
128 
129  if (true === $this->_parameters->getParameter('serialize_content')) {
130  $content = unserialize($content);
131  }
132 
133  return $content;
134  }
clean($lifetime=Cache::CLEAN_ALL)
Definition: Memcache.php:144
$content
Definition: Hoa.php:119

Here is the call graph for this function:

Hoa\Cache\Backend\Memcache::remove ( )

Remove a memcache items.

Returns
void

Definition at line 172 of file Memcache.php.

173  {
174  $this->setMemcache();
175  $this->_memcache->delete($this->getIdMd5());
176 
177  return;
178  }

Here is the call graph for this function:

Hoa\Cache\Backend\Memcache::setMemcache ( )
protected

Set Memcache object.

Returns
bool

Definition at line 185 of file Memcache.php.

186  {
187  if (is_object($this->_memcache)) {
188  return true;
189  }
190 
191  $this->_memcache = new \Memcache();
192  $this->_memcache->addServer(
193  $this->_parameters->getParameter('memcache.database.host'),
194  $this->_parameters->getParameter('memcache.database.port'),
195  $this->_parameters->getParameter('memcache.database.persistent')
196  );
197 
198  return true;
199  }

Here is the caller graph for this function:

Hoa\Cache\Backend\Memcache::store (   $data)

Save cache content into a Memcache items.

Parameters
mixed$dataData to store.
Returns
void

Definition at line 89 of file Memcache.php.

90  {
91  $this->setMemcache();
92  $this->clean();
93 
94  if (true === $this->_parameters->getParameter('serialize_content')) {
95  $data = serialize($data);
96  }
97 
98  $flag =
99  $this->_parameters->getParameter('memcache.compress.active')
100  ? MEMCACHE_COMPRESSED
101  : 0;
102  $lifetime = $this->_parameters->getParameter('lifetime');
103 
104  if ($lifetime > 2592000) {
105  // 30 days.
106  $lifetime = 2592000;
107  }
108 
109  return $this->_memcache->set(
110  $this->getIdMd5(),
111  $data,
112  $flag,
113  $lifetime
114  );
115  }
clean($lifetime=Cache::CLEAN_ALL)
Definition: Memcache.php:144

Here is the call graph for this function:

Member Data Documentation

Hoa\Cache\Backend\Memcache::$_memcache = null
protected

Definition at line 58 of file Memcache.php.


The documentation for this class was generated from the following file: