Rewrite Store::load_in_cache() to check cache before loading
This commit is contained in:
parent
6c92b2300c
commit
f802b00974
1 changed files with 14 additions and 13 deletions
|
@ -60,21 +60,22 @@ impl Store {
|
||||||
-> Option<Rc<RefCell<File>>>
|
-> Option<Rc<RefCell<File>>>
|
||||||
where HP: FileHeaderParser
|
where HP: FileHeaderParser
|
||||||
{
|
{
|
||||||
let idstr : String = id.clone().into();
|
self.load(&id).or({
|
||||||
let path = format!("{}/{}-{}.imag", self.storepath, m.name(), idstr);
|
let idstr : String = id.clone().into();
|
||||||
debug!("Loading path = '{}'", path);
|
let path = format!("{}/{}-{}.imag", self.storepath, m.name(), idstr);
|
||||||
let mut string = String::new();
|
debug!("Loading path = '{}'", path);
|
||||||
|
let mut string = String::new();
|
||||||
|
|
||||||
FSFile::open(&path).map(|mut file| {
|
FSFile::open(&path).map(|mut file| {
|
||||||
file.read_to_string(&mut string)
|
file.read_to_string(&mut string)
|
||||||
.map_err(|e| error!("Failed reading file: '{}'", path));
|
.map_err(|e| error!("Failed reading file: '{}'", path));
|
||||||
});
|
});
|
||||||
|
|
||||||
parser.read(string).map(|(header, data)| {
|
parser.read(string).map(|(header, data)| {
|
||||||
self.new_file_from_parser_result(m, id.clone(), header, data);
|
self.new_file_from_parser_result(m, id.clone(), header, data);
|
||||||
});
|
self.load(&id)
|
||||||
|
}).unwrap_or(None)
|
||||||
self.load(&id)
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue