So I've just started to learn about how to use memcache yesterday. So there's still a lot to do. So far I've got down how to install it, and saw a couple tutorials on how to use it. But they all explain how to type it out statically. I do all my db queries in classes and run through the data returned with a foreach loop. I got it working without any compile errors, but the memcache won't actually work. I'm confused as to why. My class is set up this way.
class Feed extends Database
{
private $Memcache;
public function __construct()
{
parent::__construct();
$this->Memcache = new Memcache;
} //end __construct
public function getFeed ($var)
{
$feed = array(); //Initialize an empty array
$this->Memcache->connect('localhost', 11211);
$key = "SELECT col FROM table WHERE value = " . $var . " ORDER BY timestamp DESC LIMIT 30";
$cache = $this->Memcache->get($key);
if ($cache)
{
$feed = '';
}
else
{
//Query the database
$Statement = $this->Database->prepare("SELECT col FROM table WHERE value = ? ORDER BY timestamp DESC LIMIT 30");
$Statement->execute(array($var));
while($row = $Statement->fetch(PDO::FETCH_ASSOC))
{
$feed[] = array("row1" => $row["col1"],
"row2" => $row["col2"] );
}
$this->Memcache->set($key, $row, 0, 40); // Store the result of the query for 40 seconds
}
return $feed;
} //end getFeed
} //end Feed
The output is set up like so
<?php foreach ($Feed->getFeed($var) as $feed): ?>
<p><?php echo $feed["row1"]; ?></p>
<?php endforeach; ?>
So obviously if the memcache was working their would be a compile error since I run through the $feed with a foreach loop. Since I'm limited in my knowledge of memcache do any of you know why it isn't retrieve the data.
Thank you do much!