pub struct CacheSyncService { /* private fields */ }Expand description
Service that syncs the cache with on-chain events
Provides both polling-based and manual event processing for cache invalidation.
§Example
ⓘ
use blueprint_tangle_extra::cache::{CacheSyncService, shared_cache};
let cache = shared_cache();
let sync_service = CacheSyncService::new(client, cache.clone());
// Option 1: Poll for events periodically
loop {
let events_processed = sync_service.poll_and_sync(last_block).await?;
tokio::time::sleep(Duration::from_secs(12)).await;
}
// Option 2: Process events from your own subscription
sync_service.process_logs(&logs);Implementations§
Source§impl CacheSyncService
impl CacheSyncService
Sourcepub fn new(client: Arc<TangleClient>, cache: SharedServiceConfigCache) -> Self
pub fn new(client: Arc<TangleClient>, cache: SharedServiceConfigCache) -> Self
Create a new cache sync service
Sourcepub fn with_services(self, services: Vec<u64>) -> Self
pub fn with_services(self, services: Vec<u64>) -> Self
Only watch specific services
Sourcepub fn from_block(self, block: u64) -> Self
pub fn from_block(self, block: u64) -> Self
Set the starting block for polling
Sourcepub async fn poll_and_sync(&self) -> Result<usize, CacheError>
pub async fn poll_and_sync(&self) -> Result<usize, CacheError>
Poll for new events and sync the cache
Returns the number of events processed.
Sourcepub fn process_logs(&self, logs: &[Log]) -> usize
pub fn process_logs(&self, logs: &[Log]) -> usize
Process a batch of logs and invalidate cache as needed
Returns the number of events processed.
Sourcepub fn parse_log(&self, log: &Log) -> Option<CacheInvalidationEvent>
pub fn parse_log(&self, log: &Log) -> Option<CacheInvalidationEvent>
Parse a log into a cache invalidation event
Sourcepub fn process_event(&self, event: CacheInvalidationEvent)
pub fn process_event(&self, event: CacheInvalidationEvent)
Process a single event manually (useful for testing or custom event sources)
Sourcepub fn last_block(&self) -> u64
pub fn last_block(&self) -> u64
Get the last processed block number
Auto Trait Implementations§
impl !Freeze for CacheSyncService
impl !RefUnwindSafe for CacheSyncService
impl Send for CacheSyncService
impl Sync for CacheSyncService
impl Unpin for CacheSyncService
impl UnsafeUnpin for CacheSyncService
impl !UnwindSafe for CacheSyncService
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more