Add no-expiry option to cached query functions, and fix cache invalidation bug

develop
Sven Slootweg 12 years ago
parent 4385243b9c
commit abb0712c97

@ -371,11 +371,11 @@ abstract class CPHPDatabaseRecordClass extends CPHPBaseClass
/* Temporary implementation to make old style queries play nice with PDO code. */
if(strpos($this->verify_query, ":Id") !== false)
{
$this->verify_query = str_replace(":Id", "%d", $this->verify_query);
$this->verify_query = str_replace(":Id", "'%d'", $this->verify_query);
}
$query = sprintf($this->verify_query, $this->sId);
if($result = mysql_query_cached($query))
if($result = mysql_query_cached($query, 0))
{
$insert_mode = CPHP_INSERTMODE_UPDATE;
}
@ -542,9 +542,24 @@ abstract class CPHPDatabaseRecordClass extends CPHPBaseClass
public function PurgeCache()
{
$query = sprintf($this->fill_query, $this->sId);
if(strpos($this->fill_query, ":Id") !== false)
{
$fill_query = str_replace(":Id", "'%d'", $this->fill_query);
}
else
{
$fill_query = $this->fill_query;
}
$query = sprintf($fill_query, $this->sId);
$key = md5($query) . md5($query . "x");
$query_hash = md5($this->fill_query);
$parameter_hash = md5(serialize(array(':Id' => (int) $this->sId)));
$pdo_key = $query_hash . $parameter_hash;
mc_delete($key);
mc_delete($pdo_key);
}
public function RenderTemplate($template = "")

@ -39,6 +39,7 @@ function mc_get($key)
else
{
$get_result = $cphp_memcache->get($key);
if($get_result !== false)
{
return $get_result;
@ -84,7 +85,8 @@ function mc_delete($key)
}
else
{
return $cphp_memcache->delete($key);
$delete_result = $cphp_memcache->delete($key);
return $delete_result;
}
}
@ -142,7 +144,10 @@ function mysql_query_cached($query, $expiry = 60, $key = "")
{
if(count($data) > 0)
{
mc_set($key, $result, $expiry);
if($expiry != 0)
{
mc_set($key, $result, $expiry);
}
$return_object->source = "database";
$return_object->data = $result;

@ -61,7 +61,7 @@ class CachedPDO extends PDO
$query_hash = md5($query);
$parameter_hash = md5(serialize($parameters));
$cache_hash = $query_hash . $parameter_hash;
$return_object = new stdClass;
if($result = mc_get($cache_hash))
@ -96,7 +96,10 @@ class CachedPDO extends PDO
{
if(count($result) > 0)
{
mc_set($cache_hash, $result, $expiry);
if($expiry != 0)
{
mc_set($cache_hash, $result, $expiry);
}
$return_object->source = "database";
$return_object->data = $result;

Loading…
Cancel
Save