-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
In memory ledger response caching (#855)
In memory ledger response caching (#855) Signed-off-by: Miroslav Kovar <miroslav.kovar@absa.africa>
- Loading branch information
Showing
14 changed files
with
430 additions
and
22 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
aries_vcx_core/src/ledger/response_cacher/in_memory/config.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
use std::{num::NonZeroUsize, time::Duration}; | ||
|
||
use crate::errors::error::{AriesVcxCoreError, AriesVcxCoreErrorKind}; | ||
|
||
pub struct InMemoryResponseCacherConfig { | ||
ttl: Duration, | ||
capacity: NonZeroUsize, | ||
} | ||
|
||
impl InMemoryResponseCacherConfig { | ||
pub fn builder() -> InMemoryResponseCacherConfigBuilder { | ||
InMemoryResponseCacherConfigBuilder::default() | ||
} | ||
|
||
pub fn ttl(&self) -> Duration { | ||
self.ttl | ||
} | ||
|
||
pub fn capacity(&self) -> NonZeroUsize { | ||
self.capacity | ||
} | ||
} | ||
|
||
#[derive(Default)] | ||
pub struct InMemoryResponseCacherConfigBuilder {} | ||
|
||
pub struct InMemoryResponseCacherConfigBuilderTtlSet { | ||
ttl: Duration, | ||
} | ||
|
||
pub struct InMemoryResponseCacherConfigBuilderReady { | ||
ttl: Duration, | ||
capacity: NonZeroUsize, | ||
} | ||
|
||
impl InMemoryResponseCacherConfigBuilder { | ||
pub fn ttl(self, ttl: Duration) -> InMemoryResponseCacherConfigBuilderTtlSet { | ||
InMemoryResponseCacherConfigBuilderTtlSet { ttl } | ||
} | ||
} | ||
|
||
impl InMemoryResponseCacherConfigBuilderTtlSet { | ||
pub fn capacity(self, capacity: usize) -> Result<InMemoryResponseCacherConfigBuilderReady, AriesVcxCoreError> { | ||
let capacity = NonZeroUsize::new(capacity).ok_or(AriesVcxCoreError::from_msg( | ||
AriesVcxCoreErrorKind::InvalidOption, | ||
"Failed to parse cache capacity into NonZeroUsize", | ||
))?; | ||
Ok(InMemoryResponseCacherConfigBuilderReady { | ||
ttl: self.ttl, | ||
capacity, | ||
}) | ||
} | ||
} | ||
|
||
impl InMemoryResponseCacherConfigBuilderReady { | ||
pub fn build(self) -> InMemoryResponseCacherConfig { | ||
InMemoryResponseCacherConfig { | ||
ttl: self.ttl, | ||
capacity: self.capacity, | ||
} | ||
} | ||
} |
Oops, something went wrong.