From dae0c1ded2bdba958ada3ba6f44b018cc959fbeb Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 24 Jan 2012 17:04:49 -0800 Subject: [PATCH] more robust cache api handling (was throwing errors on occasion) --- include/cache.php | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/include/cache.php b/include/cache.php index 082974c61a..3c8a3f7138 100755 --- a/include/cache.php +++ b/include/cache.php @@ -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(){ -- 2.39.5