1
1
Fork 0

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 {
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)
);
@ -14,11 +14,22 @@
}
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)
);
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(){
q("DELETE FROM `cache` WHERE `updated` < '%s'",