Skip to content

Commit

Permalink
Perf glory on Library
Browse files Browse the repository at this point in the history
  • Loading branch information
KrisJordan committed Nov 13, 2008
1 parent 2382336 commit f0749f7
Show file tree
Hide file tree
Showing 8 changed files with 217 additions and 115 deletions.
45 changes: 45 additions & 0 deletions lib/recess/cache/ApcCacheProvider.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php
class ApcCacheProvider implements ICacheProvider {
protected $reportsTo;

function reportsTo(ICacheProvider $cache) {
if(!$cache instanceof ICacheProvider) {
$cache = new NoOpCacheProvider();
}

if(isset($this->reportsTo)) {
$temp = $this->reportsTo;
$this->reportsTo = $cache;
$this->reportsTo->reportsTo($temp);
} else {
$this->reportsTo = $cache;
}
}

function set($key, $value, $duration = 0) {
apc_store($key, $value, $duration);
$this->reportsTo->set($key, $value, $duration);
}

function get($key) {
$result = apc_fetch($key);
if($result === false) {
$result = $this->reportsTo->get($key);
if($result !== false) {
$this->set($key, $result);
}
}
return $result;
}

function delete($key) {
apc_delete($key);
$this->reportsTo->delete($key);
}

function clear() {
apc_clear_cache('user');
$this->reportsTo->clear();
}
}
?>
42 changes: 32 additions & 10 deletions lib/recess/cache/Cache.class.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
<?php
require_once('ICacheProvider.class.php');
require_once('NoOpCacheProvider.class.php');

/**
* Cache is a low level service offering volatile key-value pair
* storage.
*
* @author Kris Jordan
* @todo Actually write tests for this this (and implement subclasses.)
* */
class Cache {
abstract class Cache {
protected static $reportsTo;

static function reportsTo(ICacheProvider $cache) {
Expand All @@ -26,22 +23,47 @@ static function reportsTo(ICacheProvider $cache) {
}
}

static function set($key, $value, $timeout = 0) {
return self::$reportsTo->set($key, $value);
static function set($key, $value, $duration = 0) {
return self::$reportsTo->set($key, $value, $duration);
}

static function get($key) {
return self::$reportsTo->get($key);
}

static function clear($key) {
return self::$reportsTo->clear($key);
static function delete($key) {
return self::$reportsTo->delete($key);
}

static function flush() {
return self::$reportsTo->flush();
static function clear() {
return self::$reportsTo->clear();
}
}

/**
* Common interface for caching subsystems.
* @author Kris Jordan
*/
interface ICacheProvider {
/**
* Enter description here...
*
* @param string $key
* @param mixed $value
* @param unknown_type $duration
*/
function set($key, $value, $duration = 0);
function get($key);
function delete($key);
function clear();
}

class NoOpCacheProvider implements ICacheProvider {
function set($key, $value, $duration = 0) {}
function get($key) { return false; }
function delete($key) {}
function clear() {}
}

Cache::reportsTo(new NoOpCacheProvider());
?>
20 changes: 0 additions & 20 deletions lib/recess/cache/ICacheProvider.class.php

This file was deleted.

9 changes: 0 additions & 9 deletions lib/recess/cache/NoOpCacheProvider.class.php

This file was deleted.

1 change: 0 additions & 1 deletion lib/recess/framework/Coordinator.class.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php
Library::import('Config');

Library::import('recess.http.ForwardingResponse');
/**
Expand Down
Loading

0 comments on commit f0749f7

Please sign in to comment.