summaryrefslogtreecommitdiff
path: root/functions.php
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2010-01-20 12:50:19 +0300
committerAndrew Dolgov <[email protected]>2010-01-20 12:50:19 +0300
commit602690e57700004449fe213262a73197ef39bd1f (patch)
tree3a26b951c73a651d078a21bf23e6f2fb4c5f83ab /functions.php
parentc517f9b7e59dd7bafd9c8fe928d10eb92d845478 (diff)
update_rss_feed: use memcache
Diffstat (limited to 'functions.php')
-rw-r--r--functions.php68
1 files changed, 41 insertions, 27 deletions
diff --git a/functions.php b/functions.php
index a7564dbc6..04cda3d1d 100644
--- a/functions.php
+++ b/functions.php
@@ -510,6 +510,8 @@
function update_rss_feed($link, $feed_url, $feed, $ignore_daemon = false) {
+ global $memcache;
+
if (!$_REQUEST["daemon"] && !$ignore_daemon) {
return false;
}
@@ -600,38 +602,50 @@
error_reporting(0);
}
- if (!$use_simplepie) {
- $rss = fetch_rss($fetch_url);
- } else {
- if (!is_dir(SIMPLEPIE_CACHE_DIR)) {
- mkdir(SIMPLEPIE_CACHE_DIR);
- }
-
- $rss = new SimplePie();
- $rss->set_useragent(SIMPLEPIE_USERAGENT . MAGPIE_USER_AGENT_EXT);
-# $rss->set_timeout(10);
- $rss->set_feed_url($fetch_url);
- $rss->set_output_encoding('UTF-8');
-
- if (SIMPLEPIE_CACHE_IMAGES && $cache_images) {
- if (defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug']) {
- _debug("enabling image cache");
- }
-
- $rss->set_image_handler('./image.php', 'i');
- }
+ $obj_id = md5("FEEDOBJ:$fetch_url");
+ if ($memcache && $obj = $memcache->get($obj_id)) {
if (defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug']) {
- _debug("feed update interval (sec): " .
- get_feed_update_interval($link, $feed)*60);
+ _debug("update_rss_feed: data found in memcache [$obj_id]");
}
+ $rss = $obj;
+ } else {
- if (is_dir(SIMPLEPIE_CACHE_DIR)) {
- $rss->set_cache_location(SIMPLEPIE_CACHE_DIR);
- $rss->set_cache_duration(get_feed_update_interval($link, $feed) * 60);
+ if (!$use_simplepie) {
+ $rss = fetch_rss($fetch_url);
+ } else {
+ if (!is_dir(SIMPLEPIE_CACHE_DIR)) {
+ mkdir(SIMPLEPIE_CACHE_DIR);
+ }
+
+ $rss = new SimplePie();
+ $rss->set_useragent(SIMPLEPIE_USERAGENT . MAGPIE_USER_AGENT_EXT);
+ # $rss->set_timeout(10);
+ $rss->set_feed_url($fetch_url);
+ $rss->set_output_encoding('UTF-8');
+
+ if (SIMPLEPIE_CACHE_IMAGES && $cache_images) {
+ if (defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug']) {
+ _debug("enabling image cache");
+ }
+
+ $rss->set_image_handler('./image.php', 'i');
+ }
+
+ if (defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug']) {
+ _debug("feed update interval (sec): " .
+ get_feed_update_interval($link, $feed)*60);
+ }
+
+ if (is_dir(SIMPLEPIE_CACHE_DIR)) {
+ $rss->set_cache_location(SIMPLEPIE_CACHE_DIR);
+ $rss->set_cache_duration(get_feed_update_interval($link, $feed) * 60);
+ }
+
+ $rss->init();
}
-
- $rss->init();
+
+ if ($rss && $memcache) $memcache->add($obj_id, $rss, 0, 300);
}
// print_r($rss);