Skip to content

Commit

Permalink
chore: add rwlock cache
Browse files Browse the repository at this point in the history
  • Loading branch information
renancloudwalk committed Mar 7, 2024
1 parent 0ed2831 commit 9ced06a
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/infra/postgres.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
//! PostgreSQL client.
use std::collections::HashMap;
use std::sync::Arc;
use std::time::Duration;

use anyhow::anyhow;
use sqlx::postgres::PgPoolOptions;
use sqlx::PgPool;
use tokio::sync::RwLock;

use crate::eth::primitives::Address;
use crate::eth::primitives::BlockNumber;
use crate::eth::primitives::SlotIndex;
use crate::eth::primitives::SlotValue;
use crate::log_and_err;

#[derive(Debug, Clone)]
pub struct Postgres {
pub connection_pool: PgPool,
pub sload_cache: Arc<RwLock<HashMap<(Address, SlotIndex), (SlotValue, BlockNumber)>>>,
}

impl Postgres {
Expand All @@ -28,7 +36,10 @@ impl Postgres {
anyhow!("failed to start postgres client")
})?;

let postgres = Self { connection_pool };
let postgres = Self {
connection_pool,
sload_cache: Arc::new(RwLock::new(HashMap::new())),
};

Ok(postgres)
}
Expand Down

0 comments on commit 9ced06a

Please sign in to comment.