Skip to content

Caching #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions Cache/AdapterInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

/**
* @category CheddarGetter
* @package CheddarGetter
* @author Marc Guyer <marc@cheddargetter.com>
*/
/**
* Adapter interface for caching responses
* @category CheddarGetter
* @package CheddarGetter
* @author Ben Serrette <ben@squadedit.com>
*/

interface CheddarGetter_Cache_AdapterInterface {

function __construct();
function load($key);
function save($key, $value);
function remove($key);

}
32 changes: 32 additions & 0 deletions Cache/ApcAdapter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

class CheddarGetter_Cache_ApcAdapter implements CheddarGetter_Cache_AdapterInterface
{
public function __construct(){
// echo "Making APC \n";
}

public function save($key, $value)
{
$key = "CGCaching_".$key;
apc_store($key, $value);
// echo "Saving \n";
}
public function remove($key)
{
$key = "CGCaching_".$key;
apc_delete($key);
// echo "Removing \n";
}
public function load($key)
{

$key = "CGCaching_".$key;
$value = false;
if(apc_fetch($key))
$value = apc_fetch($key);
// echo "Loading \n";
return $value;
}
}

35 changes: 35 additions & 0 deletions Cache/MemcacheAdapter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

class CheddarGetter_Cache_MemcacheAdapter implements CheddarGetter_Cache_AdapterInterface
{
private $cache;
public function __construct()
{
$this->cache = new Memcache;
$this->cache->connect("localhost");
//echo "making memcache\n";
}

public function save($key, $value)
{
$key = "CGCaching_".$key;
$this->cache->set($key, $value);
//echo "Saving \n";
}
public function remove($key)
{
$key = "CGCaching_".$key;
$this->cache->delete($key);
//echo "Removing\n";
}
public function load($key)
{
$value = false;
$key = "CGCaching_".$key;
if($this->cache->get($key))
$value = $this->cache->get($key);
//echo "Loading \n";
return $value;
}
}

32 changes: 32 additions & 0 deletions Cache/SessionAdapter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

class CheddarGetter_Cache_SessionAdapter implements CheddarGetter_Cache_AdapterInterface
{
public function __construct(){
// echo "making Session \n";
}

public function save($key, $value)
{
if(!isset($_SESSION["CGCaching"]))
$_SESSION["CGCaching"] = array();
$_SESSION["CGCaching"][$key] = $value;
// echo "Saving \n";
}
public function remove($key)
{
if(!isset($_SESSION["CGCaching"][$key]))
unset($_SESSION["CGCaching"][$key]);
// echo "Removing \n";
}
public function load($key)
{
$value = false;
if(isset($_SESSION["CGCaching"][$key]))
$value = $_SESSION["CGCaching"][$key];
// echo "Loading \n";
return $value;
}
}


Loading