From 37fe05a345d3a4f3192f38e2861d56ac2f9d3046 Mon Sep 17 00:00:00 2001 From: dhawes Date: Fri, 21 Jan 2005 03:23:26 +0000 Subject: [PATCH] added in an extra layer of cache. The rendered string is now cached in block's config. If the config settings are changed the config entry is overwritten and the cached string is lost - which is perfect - it gets rebuilt to the new specifications on next page load. If the filesystem cache has expired then the stored config string is ignored and a fresh read is sought. --- blocks/rss_client/block_rss_client.php | 27 +++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/blocks/rss_client/block_rss_client.php b/blocks/rss_client/block_rss_client.php index 886663f31f..ddc168144d 100644 --- a/blocks/rss_client/block_rss_client.php +++ b/blocks/rss_client/block_rss_client.php @@ -75,16 +75,16 @@ class block_rss_client extends block_base { //if the user is an admin or course teacher then allow the user to //assign categories to other uses than personal if ( isadmin() || $submitters == 0 || ($submitters == 2 && $isteacher) ) { - $output .= '
'. get_string('block_rss_feeds_add_edit', 'block_rss_client') .'


'; + $output .= '
'. get_string('block_rss_feeds_add_edit', 'block_rss_client') .'


'; } } // Daryl Hawes note: if count of rssidarray is greater than 1 // we should possibly display a drop down menu of selected feed titles // so user can select a single feed to view (similar to RSSFeed) - $numids = count($rssidarray); - $count = 0; if (!empty($rssidarray)) { + $numids = count($rssidarray); + $count = 0; foreach ($rssidarray as $rssid) { $output .= $this->get_rss_by_id($rssid, $display_description, $shownumentries, ($numids > 1) ? true : false); if ($numids > 1 && $count != $numids -1) { @@ -109,13 +109,23 @@ class block_rss_client extends block_base { function instance_allow_config() { return true; } - + /** * */ function get_rss_by_id($rssid, $display_description, $shownumentries, $showtitle=false) { global $CFG; - $returnstring = ''; + $returnstring = ''; + + // use rsslib.php function to verify that the cache feed file + // exists and has not timed out. + if (rss_cache_valid_by_id($rssid) && isset($this->config->{$rssid})) { + // If cache has not timed out and we have cached the display string + // in block config return that rather than opening and reading + // from file and reparsing the cached xml + return stripslashes_safe($this->config->{'rssid'.$rssid}); + } + $rss_record = get_record('block_rss_client', 'id', $rssid); if (isset($rss_record) && isset($rss_record->id)) { $rss = rss_get_feed($rss_record->id, $rss_record->url, $rss_record->type); @@ -162,8 +172,11 @@ class block_rss_client extends block_base { $this->title = $feedtitle; } $returnstring .= '
'; + + // store config setting for this rssid so we do not need to read from file each time + $this->config->{'rssid'.$rssid} = addslashes($returnstring); + $this->instance_config_save($this->config); return $returnstring; } - } -?> +?> \ No newline at end of file -- 2.39.5