Browse Source

Working on allowing the cache to be turned off

develop
Drew Short 9 years ago
parent
commit
1d408c2905
  1. 2
      Cargo.toml
  2. 7
      src/cache.rs
  3. 2
      src/lib.rs

2
Cargo.toml

@ -1,6 +1,6 @@
[package]
name = "pihash"
version = "0.2.5"
version = "0.2.6"
authors = ["Drew Short <warrick@sothr.com>"]
description = "A simple library for generating perceptual hashes for images and comparing images based on their perceptual hashes."
repository = "https://github.com/warricksothr/Perceptual-Image-Hashing/"

7
src/cache.rs

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

2
src/lib.rs

@ -19,7 +19,7 @@ use hash::PerceptualHash;
use std::ffi::CStr;
use cache::Cache;
static LIB_CACHE: Cache<'static> = Cache { cache_dir: cache::CACHE_DIR };
static LIB_CACHE: Cache<'static> = Cache { cache_dir: cache::CACHE_DIR, use_cache: true };
/**
* Prepare the library for work.

Loading…
Cancel
Save