X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Fcache.php;h=360c4acbdbadd285225f848149a3d2c778bc8576;hb=d1a0206cdd1a65b08feb16197fe2236c8e1a8037;hp=082974c61a907f8a42e593f88383dd586b585701;hpb=4218e3f4945af7101c626852bda09d2c591b8e0c;p=friendica.git diff --git a/include/cache.php b/include/cache.php index 082974c61a..360c4acbdb 100644 --- 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,11 +14,40 @@ } public static function set($key,$value) { - q("INSERT INTO `cache` VALUES ('%s','%s','%s')", - dbesc($key), - dbesc($value), - dbesc(datetime_convert())); + + q("REPLACE INTO `cache` (`k`,`v`,`updated`) VALUES ('%s','%s','%s')", + dbesc($key), + dbesc($value), + dbesc(datetime_convert())); } + + +/* + * + * Leaving this legacy code temporaily to see how REPLACE fares + * as opposed to non-atomic checks when faced with fast moving key duplication. + * As a MySQL extension it isn't portable, but we're not yet very portable. + */ + +/* + * $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'",