]> git.mxchange.org Git - friendica.git/commitdiff
use mysql replace on cache items
authorfriendica <info@friendica.com>
Wed, 2 May 2012 23:27:19 +0000 (16:27 -0700)
committerfriendica <info@friendica.com>
Wed, 2 May 2012 23:27:19 +0000 (16:27 -0700)
include/cache.php

index 3c8a3f7138b4d7d5c1da52fe86ae99b62283bec8..360c4acbdbadd285225f848149a3d2c778bc8576 100644 (file)
                }
                
                public static function set($key,$value) {
-                       $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')",
+
+                       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'",