Skip to content

Commit

Permalink
Merge pull request #27 from brandonsavage/interface_update
Browse files Browse the repository at this point in the history
Updating and adding methods to the Bouncer cache interface.
  • Loading branch information
brandonsavage committed Aug 21, 2013
2 parents 226d71c + be1cd57 commit e8dc226
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 5 deletions.
56 changes: 56 additions & 0 deletions bouncer/php/lib/cache_interface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

interface Cache_Interface {

/**
* Get an item from the cache, if it exists
* @return mixed item if found, else false
*/
public function get($key);

/**
* Store an item in the cache. Replaces an existing item.
* @return bool success
*/
public function set($key, $var, $flag = null, $expire);

/**
* Store an item in the cache. Returns false if the key is
* already present in the cache.
* @return bool success
*/
public function add($key, $var, $flag = null, $expire);

/**
* Store an item in the cache. Returns false if the key did
* NOT exist in the cache before.
* @return bool success
*/
public function replace($key, $var, $flag = null, $expire);

/**
* Close the connection to _ALL_ cache servers
* @return bool success
*/
public function close();

/**
* Delete something off the cache
* @return bool success
*/
public function delete($key, $timeout = null);

/**
* Returns key in the appropriate namespace.
* @param string $key memcache key
* @return string Namespaced key
*/
public function namespaceKey($key);

/**
* Flush the cache
* @return bool success
*/
public function flush();

}
6 changes: 3 additions & 3 deletions bouncer/php/lib/memcaching.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,17 @@
*
* ***** END LICENSE BLOCK ***** */

interface Memcache_Interface {}
require 'cache_interface.php';

/**
* This model is an interface to Memcache.
* It's called Memcaching to not interfere with the actual Memcache class.
*/
class Memcaching implements Memcache_Interface {
class Memcaching implements Cache_Interface {
var $cache; // holds the memcache object
var $memcacheConnected; // did we find a valid memcache server?
function Memcaching() {
function __construct() {
global $memcache_config;

if (class_exists('Memcache') && defined('CACHE') && CACHE)
Expand Down
2 changes: 1 addition & 1 deletion bouncer/php/lib/sdo2.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class SDO2 {
protected $db_read;
protected $db_details;

public function __construct(Memcache_Interface $mc, array $dbwrite = array(), array $dbread = array()) {
public function __construct(Cache_Interface $mc, array $dbwrite = array(), array $dbread = array()) {
$this->mc = $mc;
if(empty($dbwrite) && empty($dbread)) {
throw new Exception('No credentials supplied for database connection');
Expand Down
2 changes: 1 addition & 1 deletion bouncer/tests/mocks/memcaching.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* This model is an interface to Memcache.
* It's called Memcaching to not interfere with the actual Memcache class.
*/
class Memcaching_Mock implements Memcache_Interface {
class Memcaching_Mock implements Cache_Interface {

function get($key) {
return false;
Expand Down

0 comments on commit e8dc226

Please sign in to comment.