|
@ -48,10 +48,11 @@ impl PartialEq<CacheMetadata> for CacheMetadata { |
|
|
*/
|
|
|
*/
|
|
|
pub struct Cache<'a> {
|
|
|
pub struct Cache<'a> {
|
|
|
pub cache_dir: &'a str,
|
|
|
pub cache_dir: &'a str,
|
|
|
|
|
|
pub use_cache: bool,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
impl<'a> Default for Cache<'a> {
|
|
|
impl<'a> Default for Cache<'a> {
|
|
|
fn default() -> Cache<'a> { Cache {cache_dir: CACHE_DIR } }
|
|
|
|
|
|
|
|
|
fn default() -> Cache<'a> { Cache {cache_dir: CACHE_DIR, use_cache: true } }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
impl<'a> Cache<'a> {
|
|
|
impl<'a> Cache<'a> {
|
|
@ -172,6 +173,7 @@ impl<'a> Cache<'a> { |
|
|
path: &Path,
|
|
|
path: &Path,
|
|
|
size: u32)
|
|
|
size: u32)
|
|
|
-> Option<ImageBuffer<image::Luma<u8>, Vec<u8>>> {
|
|
|
-> Option<ImageBuffer<image::Luma<u8>, Vec<u8>>> {
|
|
|
|
|
|
if self.use_cache {
|
|
|
let hash = self.get_file_hash(&path);
|
|
|
let hash = self.get_file_hash(&path);
|
|
|
match hash {
|
|
|
match hash {
|
|
|
Ok(sha1) => {
|
|
|
Ok(sha1) => {
|
|
@ -199,6 +201,7 @@ impl<'a> Cache<'a> { |
|
|
None
|
|
|
None
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
} else { None }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
/**
|
|
@ -263,6 +266,7 @@ impl<'a> Cache<'a> { |
|
|
path: &Path,
|
|
|
path: &Path,
|
|
|
size: u32)
|
|
|
size: u32)
|
|
|
-> Option<Vec<Vec<f64>>> {
|
|
|
-> Option<Vec<Vec<f64>>> {
|
|
|
|
|
|
if self.use_cache {
|
|
|
let hash = self.get_file_hash(&path);
|
|
|
let hash = self.get_file_hash(&path);
|
|
|
match hash {
|
|
|
match hash {
|
|
|
Ok(sha1) => {
|
|
|
Ok(sha1) => {
|
|
@ -305,6 +309,7 @@ impl<'a> Cache<'a> { |
|
|
None
|
|
|
None
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
} else { None }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|