more robust cache api handling (was throwing errors on occasion)

This commit is contained in:
friendica 2012-01-24 17:04:49 -08:00
parent 8ff2bb4cd3
commit dae0c1ded2

View file

@ -5,7 +5,7 @@
class Cache { class Cache {
public static function get($key){ public static function get($key){
$r = q("SELECT `v` FROM `cache` WHERE `k`='%s'", $r = q("SELECT `v` FROM `cache` WHERE `k`='%s' limit 1",
dbesc($key) dbesc($key)
); );
@ -14,10 +14,21 @@
} }
public static function set($key,$value) { public static function set($key,$value) {
q("INSERT INTO `cache` VALUES ('%s','%s','%s')", $r = q("SELECT * FROM `cache` WHERE `k`='%s' limit 1",
dbesc($key), dbesc($key)
dbesc($value), );
dbesc(datetime_convert())); if(count($r)) {
q("UPDATE `cache` SET `v` = '%s', `updated = '%s' WHERE `k` = '%s' limit 1",
dbesc($value),
dbesc(datetime_convert()),
dbesc($key));
}
else {
q("INSERT INTO `cache` (`k`,`v`,`updated`) VALUES ('%s','%s','%s')",
dbesc($key),
dbesc($value),
dbesc(datetime_convert()));
}
} }
public static function clear(){ public static function clear(){