mirror of
https://github.com/friendica/friendica
synced 2024-11-10 03:42:53 +00:00
more robust cache api handling (was throwing errors on occasion)
This commit is contained in:
parent
8ff2bb4cd3
commit
dae0c1ded2
1 changed files with 16 additions and 5 deletions
|
@ -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,11 +14,22 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
|
);
|
||||||
|
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($key),
|
||||||
dbesc($value),
|
dbesc($value),
|
||||||
dbesc(datetime_convert()));
|
dbesc(datetime_convert()));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static function clear(){
|
public static function clear(){
|
||||||
q("DELETE FROM `cache` WHERE `updated` < '%s'",
|
q("DELETE FROM `cache` WHERE `updated` < '%s'",
|
||||||
|
|
Loading…
Reference in a new issue