forked from PayU-EMEA/openpayu_php
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add memchached implementation for token cache
- Loading branch information
Showing
2 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
class OauthCacheMemcached implements OauthCacheInterface | ||
{ | ||
private $memcached; | ||
|
||
/** | ||
* @param string $host | ||
* @param int $port | ||
* @param int $weight | ||
* @throws OpenPayU_Exception_Configuration | ||
*/ | ||
public function __construct($host = 'localhost', $port = 11211, $weight = 0) | ||
{ | ||
if (!class_exists('Memcached')) { | ||
throw new OpenPayU_Exception_Configuration('PHP Memcached extension not installed.'); | ||
} | ||
|
||
$this->memcached = new Memcached('PayU'); | ||
$this->memcached->addServer($host, $port, $weight); | ||
$stats = $this->memcached->getStats(); | ||
if ($stats[$host . ':' . $port]['pid'] == -1) { | ||
throw new OpenPayU_Exception_Configuration('Problem with connection to memcached server [host=' . $host . '] [port=' . $port . '] [weight=' . $weight . ']'); | ||
} | ||
} | ||
|
||
public function get($key) | ||
{ | ||
$cache = $this->memcached->get($key); | ||
return $cache === false ? null : unserialize($cache); | ||
} | ||
|
||
public function set($key, $value) | ||
{ | ||
return $this->memcached->set($key, serialize($value)); | ||
} | ||
|
||
public function invalidate($key) | ||
{ | ||
return $this->memcached->delete($key); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters