]> git.mxchange.org Git - friendica.git/commitdiff
cache api
authorFabio Comuni <fabrix.xm@gmail.com>
Mon, 24 Oct 2011 11:02:38 +0000 (13:02 +0200)
committerFabio Comuni <fabrix.xm@gmail.com>
Mon, 24 Oct 2011 11:02:38 +0000 (13:02 +0200)
boot.php
include/cache.php [new file with mode: 0644]
include/oembed.php
include/poller.php

index 017e21814bea43b2f61f5586d32ea61809e9b894..9623b4b14194596e37b4758e042f7b5469f2059e 100644 (file)
--- a/boot.php
+++ b/boot.php
@@ -6,6 +6,7 @@ require_once('include/plugin.php');
 require_once('include/text.php');
 require_once("include/pgettext.php");
 require_once('include/nav.php');
+require_once('include/cache.php');
 
 define ( 'FRIENDIKA_PLATFORM',     'Free Friendika');
 define ( 'FRIENDIKA_VERSION',      '2.3.1140' );
diff --git a/include/cache.php b/include/cache.php
new file mode 100644 (file)
index 0000000..082974c
--- /dev/null
@@ -0,0 +1,29 @@
+<?php
+       /**
+        *  cache api
+        */
+        
+       class Cache {
+               public static function get($key){
+                       $r = q("SELECT `v` FROM `cache` WHERE `k`='%s'",
+                               dbesc($key)
+                       );
+                       
+                       if (count($r)) return $r[0]['v'];
+                       return null;
+               }
+               
+               public static function set($key,$value) {
+                       q("INSERT INTO `cache` VALUES ('%s','%s','%s')",
+                               dbesc($key),
+                               dbesc($value),
+                               dbesc(datetime_convert()));
+               }
+               
+               public static function clear(){
+                       q("DELETE FROM `cache` WHERE `updated` < '%s'",
+                               dbesc(datetime_convert('UTC','UTC',"now - 30 days")));                  
+               }
+               
+       }
+        
index a8f6636ff7f480b567976e62bb87a0df4f37f996..d40ceb3fd58389f9e1999bd93318441804eb7ddd 100644 (file)
@@ -8,12 +8,9 @@ function oembed_replacecb($matches){
 
 function oembed_fetch_url($embedurl){
 
-       $r = q("SELECT v FROM `cache` WHERE k='%s'",
-                               dbesc($embedurl));
+       $txt = Cache::get($embedurl);
                                
-       if(count($r)){
-               $txt = $r[0]['v'];
-       } else {
+       if(is_null($txt)){
                $txt = "";
                
                // try oembed autodiscovery
@@ -44,10 +41,8 @@ function oembed_fetch_url($embedurl){
                if ($txt[0]!="{") $txt='{"type":"error"}';
        
                //save in cache
-               /*q("INSERT INTO `cache` VALUES ('%s','%s','%s')",
-                       dbesc($embedurl),
-                       dbesc($txt),
-                       dbesc(datetime_convert()));*/
+               Cache::set($embedurl,$txt);
+
        }
        
        $j = json_decode($txt);
@@ -154,4 +149,5 @@ function oembed_html2bbcode($text) {
        } 
 }
 
-?>
+
+
index cef0647b596f50de31f6c6f49454deb38f37de96..a19f0716f6758e7c23e0506c51cb49c06b02cc50 100644 (file)
@@ -64,8 +64,7 @@ function poller_run($argv, $argc){
        }
 
        // clear old cache
-       q("DELETE FROM `cache` WHERE `updated` < '%s'",
-               dbesc(datetime_convert('UTC','UTC',"now - 30 days")));
+       Cache::clear();
 
        $manual_id  = 0;
        $generation = 0;