Add cache to HeaderChain struct.

This commit is contained in:
Adrian Brink
2017-04-05 13:50:11 +02:00
parent e004e05037
commit 8ea25eeb3c
3 changed files with 52 additions and 14 deletions

View File

@@ -27,6 +27,10 @@ use ethcore::spec::Spec;
use io::{IoContext, IoError, IoHandler, IoService};
use util::kvdb::{Database, DatabaseConfig};
use cache::Cache;
use time::Duration;
use util::Mutex;
use super::{Client, Config as ClientConfig};
/// Errors on service initialization.
@@ -56,6 +60,8 @@ pub struct Service {
impl Service {
/// Start the service: initialize I/O workers and client itself.
pub fn start(config: ClientConfig, spec: &Spec, path: &Path) -> Result<Self, Error> {
let cache = Arc::new(Mutex::new(Cache::new(Default::default(), Duration::hours(6))));
// initialize database.
let mut db_config = DatabaseConfig::with_columns(db::NUM_COLUMNS);
@@ -78,6 +84,7 @@ impl Service {
db::COL_LIGHT_CHAIN,
spec,
io_service.channel(),
cache,
).map_err(Error::Database)?);
io_service.register_handler(Arc::new(ImportBlocks(client.clone()))).map_err(Error::Io)?;
Ok(Service {