cache api

This commit is contained in:
Fabio Comuni 2011-10-24 13:02:38 +02:00
parent d80c0da3c0
commit 306036c626
4 changed files with 37 additions and 12 deletions

View File

@ -6,6 +6,7 @@ require_once('include/plugin.php');
require_once('include/text.php'); require_once('include/text.php');
require_once("include/pgettext.php"); require_once("include/pgettext.php");
require_once('include/nav.php'); require_once('include/nav.php');
require_once('include/cache.php');
define ( 'FRIENDIKA_PLATFORM', 'Free Friendika'); define ( 'FRIENDIKA_PLATFORM', 'Free Friendika');
define ( 'FRIENDIKA_VERSION', '2.3.1140' ); define ( 'FRIENDIKA_VERSION', '2.3.1140' );

29
include/cache.php Normal file
View File

@ -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")));
}
}

View File

@ -8,12 +8,9 @@ function oembed_replacecb($matches){
function oembed_fetch_url($embedurl){ function oembed_fetch_url($embedurl){
$r = q("SELECT v FROM `cache` WHERE k='%s'", $txt = Cache::get($embedurl);
dbesc($embedurl));
if(count($r)){ if(is_null($txt)){
$txt = $r[0]['v'];
} else {
$txt = ""; $txt = "";
// try oembed autodiscovery // try oembed autodiscovery
@ -44,10 +41,8 @@ function oembed_fetch_url($embedurl){
if ($txt[0]!="{") $txt='{"type":"error"}'; if ($txt[0]!="{") $txt='{"type":"error"}';
//save in cache //save in cache
/*q("INSERT INTO `cache` VALUES ('%s','%s','%s')", Cache::set($embedurl,$txt);
dbesc($embedurl),
dbesc($txt),
dbesc(datetime_convert()));*/
} }
$j = json_decode($txt); $j = json_decode($txt);
@ -154,4 +149,5 @@ function oembed_html2bbcode($text) {
} }
} }
?>

View File

@ -64,8 +64,7 @@ function poller_run($argv, $argc){
} }
// clear old cache // clear old cache
q("DELETE FROM `cache` WHERE `updated` < '%s'", Cache::clear();
dbesc(datetime_convert('UTC','UTC',"now - 30 days")));
$manual_id = 0; $manual_id = 0;
$generation = 0; $generation = 0;