From 9ced06a9130a4e89ca7ca84d7e6a1568f9696746 Mon Sep 17 00:00:00 2001 From: renancloudwalk Date: Thu, 7 Mar 2024 08:15:49 -0300 Subject: [PATCH] chore: add rwlock cache --- src/infra/postgres.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/infra/postgres.rs b/src/infra/postgres.rs index e55072d08..4def7d643 100644 --- a/src/infra/postgres.rs +++ b/src/infra/postgres.rs @@ -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>>, } impl Postgres { @@ -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) }