Add persistent caching to Source plugin
Store and query a cache file to look for previously handled source files.
This commit is contained in:
@@ -2,11 +2,26 @@
|
|||||||
|
|
||||||
class DownloadDispatcher_Source_PluginBase extends DownloadDispatcher_PluginBase {
|
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() {
|
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)) {
|
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();
|
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;
|
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) {
|
protected function check_processed($file) {
|
||||||
|
|||||||
Reference in New Issue
Block a user