Browse Source

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

pull/29/head
friendica 10 years ago
parent
commit
dae0c1ded2
1 changed files with 16 additions and 5 deletions
  1. +16
    -5
      include/cache.php

+ 16
- 5
include/cache.php 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,10 +14,21 @@
}
public static function set($key,$value) {
q("INSERT INTO `cache` VALUES ('%s','%s','%s')",
dbesc($key),
dbesc($value),
dbesc(datetime_convert()));
$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(){


Loading…
Cancel
Save