From 0291ef051c1d194ab62b5646323a0576ceeb5fac Mon Sep 17 00:00:00 2001 From: Ben Roberts Date: Tue, 13 Dec 2011 08:29:18 +0000 Subject: [PATCH] Add persistent caching to Source plugin Store and query a cache file to look for previously handled source files. --- .../Source/PluginBase.class.php | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/source/lib/DownloadDispatcher/Source/PluginBase.class.php b/source/lib/DownloadDispatcher/Source/PluginBase.class.php index 72567c3..1ec4ed9 100644 --- a/source/lib/DownloadDispatcher/Source/PluginBase.class.php +++ b/source/lib/DownloadDispatcher/Source/PluginBase.class.php @@ -2,11 +2,26 @@ class DownloadDispatcher_Source_PluginBase extends DownloadDispatcher_PluginBase { - static protected $source_cache = array(); + static protected $cache; + + static protected $source_cache = null; + static protected $cache_file = 'source_cache'; + static protected $cache_lifetime = 86400; protected function init_cache() { + if ( ! static::$cache) { + static::$cache = DownloadDispatcher_Main::instance()->cache(); + } + + if (is_null(static::$source_cache)) { + try { + static::$source_cache = static::$cache->fetch(static::$cache_file, static::$cache_lifetime); + } catch (SihnonFramework_Exception_CacheObjectNotFound $e) { + static::$source_cache = array(); + } + } + if ( ! array_key_exists(get_called_class(), static::$source_cache)) { - // TODO - attempt to load data from persistent storage static::$source_cache[get_called_class()] = array(); } } @@ -18,7 +33,7 @@ class DownloadDispatcher_Source_PluginBase extends DownloadDispatcher_PluginBase static::$source_cache[get_called_class()][] = $file; } - // TODO - flush cache to persistent storage + static::$cache->store($cache_file, static::$source_cache); } protected function check_processed($file) {