Added caching to Sources

Added caching to Sources.
Updated the source browser to mark sources which are still cached
This commit is contained in:
2010-03-21 23:16:56 +00:00
parent b166e125f5
commit 648968bcb7
4 changed files with 44 additions and 8 deletions

View File

@@ -11,10 +11,28 @@ class HandBrakeCluster_Rips_Source {
protected $output; protected $output;
protected $titles = array(); protected $titles = array();
public function __construct($source) { public function __construct($source_filename, $use_cache) {
$this->source = $source; $this->source = $source_filename;
$this->scan(); $this->scan();
$main = HandBrakeCluster_Main::instance();
$cache = $main->cache();
$config = $main->config();
if ($use_cache) {
$cache->store($this->source, serialize($this), $config->get('rips.cache_ttl'));
}
}
public static function load($source_filename, $use_cache = true) {
$cache = HandBrakeCluster_Main::instance()->cache();
if ($use_cache && $cache->exists($source_filename)) {
return unserialize($cache->fetch($source_filename));
} else {
return new HandBrakeCluster_Rips_Source($source_filename, $use_cache);
}
} }
protected function scan() { protected function scan() {
@@ -124,6 +142,14 @@ class HandBrakeCluster_Rips_Source {
} }
} }
public static function isCached($source_filename) {
$main = HandBrakeCluster_Main::instance();
$cache = $main->cache();
$config = $main->config();
return $cache->exists($source_filename, $config->get('rips.cache_ttl'));
}
public function addTitle(HandBrakeCluster_Rips_SourceTitle $title) { public function addTitle(HandBrakeCluster_Rips_SourceTitle $title) {
$this->titles[] = $title; $this->titles[] = $title;
} }

View File

@@ -18,11 +18,10 @@ if (substr($real_source_path, 0, strlen($real_source_dir)) != $real_source_dir)
return; return;
} }
$source = new HandBrakeCluster_Rips_Source($source_path); $source = HandBrakeCluster_Rips_Source::load($source_path);
$this->smarty->assign('source_path', $source_path); $this->smarty->assign('source_path', $source_path);
$this->smarty->assign('source', $source); $this->smarty->assign('source', $source);
$this->smarty->assign('output', $source->output());
$this->smarty->assign('titles', $source->titles()); $this->smarty->assign('titles', $source->titles());
?> ?>

View File

@@ -4,7 +4,14 @@ $main = HandBrakeCluster_Main::instance();
$config = $main->config(); $config = $main->config();
$lister = new HandBrakeCluster_Rips_SourceLister($config->get('rips.source_dir')); $lister = new HandBrakeCluster_Rips_SourceLister($config->get('rips.source_dir'));
$sources = $lister->sources();
$this->smarty->assign('sources', $lister->sources()); $sources_cached = array();
foreach ($sources as $source) {
$sources_cached[$source] = HandBrakeCluster_Rips_Source::isCached($source);
}
$this->smarty->assign('sources', $sources);
$this->smarty->assign('sources_cached', $sources_cached);
?> ?>

View File

@@ -2,11 +2,15 @@
{if $sources} {if $sources}
<p> <p>
The following DVD sources are available to be ripped: The list below contains all the DVD sources that are available and ready for ripping.
</p>
<p>
Sources that have recently been scanned are marked <em>(cached)</em> and will load fairly quickly.
Sources that have not been cached will be scanned when the link is clicked, and this may take several minutes so please be patient.
</p> </p>
<ul> <ul>
{foreach from=$sources item=source} {foreach from=$sources item=source}
<li><a href="{$base_uri}browse/source-details/id/{$source|base64_encode|replace:"/":"-"}" title="View source details">{$source|escape:'html'}</a></li> <li><a href="{$base_uri}browse/source-details/id/{$source|base64_encode|replace:"/":"-"}" title="View source details">{$source|escape:'html'}</a>{if $sources_cached.$source} (cached){/if}</li>
{/foreach} {/foreach}
</ul> </ul>
{else} {else}