From 577daf5e8abc6664a02021adeb0b9496bfd53029 Mon Sep 17 00:00:00 2001 From: ajshort Date: Fri, 28 Jan 2011 17:38:08 +1100 Subject: [PATCH] Made it possible to set the cache lifetime per RSS source. --- code/model/RssContentSource.php | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/code/model/RssContentSource.php b/code/model/RssContentSource.php index 994a760..0fcaa14 100644 --- a/code/model/RssContentSource.php +++ b/code/model/RssContentSource.php @@ -12,8 +12,15 @@ */ class RssContentSource extends ExternalContentSource { + const DEFAULT_CACHE_LIFETIME = 3600; + public static $db = array( - 'Url' => 'Varchar(255)' + 'Url' => 'Varchar(255)', + 'CacheLifetime' => 'Int' + ); + + public static $defaults = array( + 'CacheLifetime' => self::DEFAULT_CACHE_LIFETIME ); protected $client; @@ -23,9 +30,12 @@ public function getCMSFields() { Requirements::css('rssconnector/css/RssContentAdmin.css'); $fields->addFieldToTab( - 'Root.Main', new TextField('Url', 'RSS/Atom Feed URL'), - 'ShowContentInMenu' - ); + 'Root.Main', + new TextField('Url', 'RSS/Atom Feed URL'), 'ShowContentInMenu'); + + $fields->addFieldToTab( + 'Root.Advanced', + new NumericField('CacheLifetime', 'Cache Lifetime (in seconds)')); if (!$this->Url || !$client = $this->getClient()) { return $fields; @@ -91,6 +101,7 @@ public function getClient() { if (!$this->client) { $this->client = new SimplePie($this->Url); $this->client->enable_cache(true); + $this->client->set_cache_duration($this->getCacheLifetime()); $this->client->set_cache_location(TEMP_FOLDER); } @@ -101,4 +112,11 @@ public function canImport() { return $this->Url && !$this->getClient()->error; } + /** + * @return int + */ + public function getCacheLifetime() { + return ($t = $this->getField('CacheLifetime')) ? $t : self::DEFAULT_CACHE_LIFETIME; + } + } \ No newline at end of file