pub struct FirestoreCache<B, LS>{ /* private fields */ }Expand description
Re-exports all public items from the cache module.
This is only available if the caching feature is enabled.
It includes types like FirestoreCache and various
caching backends and configurations.
Manages a cache of Firestore data.
FirestoreCache listens to changes in Firestore for specified targets and updates
a cache backend accordingly. It provides methods to load initial data, manage the
listener lifecycle, and access the underlying cache backend.
§Type Parameters
B: The type of the cache backend, implementingFirestoreCacheBackend.LS: The type of storage for the listener’s resume state, implementingFirestoreResumeStateStorage.
Implementations§
Source§impl FirestoreCache<FirestoreMemoryCacheBackend, FirestoreMemListenStateStorage>
impl FirestoreCache<FirestoreMemoryCacheBackend, FirestoreMemListenStateStorage>
Sourcepub fn memory(
db: &FirestoreDb,
) -> FirestoreCacheBuilder<FirestoreMemoryCacheKind>
pub fn memory( db: &FirestoreDb, ) -> FirestoreCacheBuilder<FirestoreMemoryCacheKind>
Starts building an in-memory cache.
let cache = FirestoreCache::memory(db)
.preloaded_collection("countries")
.build()
.await?;
let country: Option<String> = db
.read_through_cache(&cache)
.fluent()
.select()
.by_id_in("countries")
.obj()
.one("SE")
.await?;Sourcepub fn builder(
db: &FirestoreDb,
) -> FirestoreCacheBuilder<FirestoreMemoryCacheKind>
pub fn builder( db: &FirestoreDb, ) -> FirestoreCacheBuilder<FirestoreMemoryCacheKind>
Starts building an in-memory cache. Equivalent to FirestoreCache::memory.
Source§impl FirestoreCache<FirestorePersistentCacheBackend, FirestoreTempFilesListenStateStorage>
impl FirestoreCache<FirestorePersistentCacheBackend, FirestoreTempFilesListenStateStorage>
Sourcepub fn persistent(
db: &FirestoreDb,
) -> FirestoreCacheBuilder<FirestorePersistentCacheKind>
pub fn persistent( db: &FirestoreDb, ) -> FirestoreCacheBuilder<FirestorePersistentCacheKind>
Starts building a persistent, disk-backed cache.
let cache = FirestoreCache::persistent(db)
.data_dir("/var/cache/my-app")
.preloaded_collection("countries")
.build()
.await?;Sourcepub fn builder(
db: &FirestoreDb,
) -> FirestoreCacheBuilder<FirestorePersistentCacheKind>
pub fn builder( db: &FirestoreDb, ) -> FirestoreCacheBuilder<FirestorePersistentCacheKind>
Starts building a persistent cache. Equivalent to FirestoreCache::persistent.
Source§impl<B, LS> FirestoreCache<B, LS>where
B: FirestoreCacheBackend + Send + Sync + 'static,
LS: FirestoreResumeStateStorage + Clone + Send + Sync + 'static,
impl<B, LS> FirestoreCache<B, LS>where
B: FirestoreCacheBackend + Send + Sync + 'static,
LS: FirestoreResumeStateStorage + Clone + Send + Sync + 'static,
Sourcepub async fn new(
name: FirestoreCacheName,
db: &FirestoreDb,
backend: B,
listener_storage: LS,
) -> FirestoreResult<Self>
👎Deprecated since 0.52.0: Use the cache builder instead: FirestoreCache::memory(&db) or FirestoreCache::persistent(&db). It assigns listener targets automatically, picks a matching listener state storage and loads the cache for you. This constructor keeps working and will not be removed in 0.x.
pub async fn new( name: FirestoreCacheName, db: &FirestoreDb, backend: B, listener_storage: LS, ) -> FirestoreResult<Self>
Use the cache builder instead: FirestoreCache::memory(&db) or FirestoreCache::persistent(&db). It assigns listener targets automatically, picks a matching listener state storage and loads the cache for you. This constructor keeps working and will not be removed in 0.x.
Creates a new FirestoreCache with default options for the given name.
§Arguments
name: A unique name for this cache instance.db: A reference to theFirestoreDbclient.backend: The cache backend implementation.listener_storage: Storage for the listener’s resume state.
§Returns
A FirestoreResult containing the new FirestoreCache.
Sourcepub async fn with_options(
options: FirestoreCacheOptions,
db: &FirestoreDb,
backend: B,
listener_storage: LS,
) -> FirestoreResult<Self>
👎Deprecated since 0.52.0: Use the cache builder instead: FirestoreCache::memory(&db) or FirestoreCache::persistent(&db). It assigns listener targets automatically, picks a matching listener state storage and loads the cache for you. This constructor keeps working and will not be removed in 0.x.
pub async fn with_options( options: FirestoreCacheOptions, db: &FirestoreDb, backend: B, listener_storage: LS, ) -> FirestoreResult<Self>
Use the cache builder instead: FirestoreCache::memory(&db) or FirestoreCache::persistent(&db). It assigns listener targets automatically, picks a matching listener state storage and loads the cache for you. This constructor keeps working and will not be removed in 0.x.
Creates a new FirestoreCache with the specified options.
§Arguments
options:FirestoreCacheOptionsto configure the cache.db: A reference to theFirestoreDbclient.backend: The cache backend implementation.listener_storage: Storage for the listener’s resume state.
§Returns
A FirestoreResult containing the new FirestoreCache.
Sourcepub fn name(&self) -> &FirestoreCacheName
pub fn name(&self) -> &FirestoreCacheName
Returns the name of this cache instance.
Sourcepub async fn load(&self) -> Result<(), FirestoreError>
pub async fn load(&self) -> Result<(), FirestoreError>
Loads initial data into the cache and starts the Firestore listener.
This method typically calls the backend’s load method to determine which
Firestore targets to listen to, adds them to the internal listener, and then
starts the listener. The listener will then call the backend’s on_listen_event
method for incoming changes.
§Returns
A Result indicating success or failure.
Sourcepub async fn shutdown(&self) -> Result<(), FirestoreError>
pub async fn shutdown(&self) -> Result<(), FirestoreError>
Shuts down the Firestore listener and the cache backend.
§Returns
A Result indicating success or failure.
Sourcepub fn backend(&self) -> Arc<B> ⓘ
pub fn backend(&self) -> Arc<B> ⓘ
Returns a thread-safe reference-counted pointer to the cache backend.
Sourcepub async fn invalidate_all(&self) -> FirestoreResult<()>
pub async fn invalidate_all(&self) -> FirestoreResult<()>
Invalidates all data in the cache.
This calls the invalidate_all method on the cache backend.
§Returns
A FirestoreResult indicating success or failure.
Auto Trait Implementations§
impl<B, LS> !Freeze for FirestoreCache<B, LS>
impl<B, LS> !RefUnwindSafe for FirestoreCache<B, LS>
impl<B, LS> !UnwindSafe for FirestoreCache<B, LS>
impl<B, LS> Send for FirestoreCache<B, LS>where
LS: Send,
impl<B, LS> Sync for FirestoreCache<B, LS>where
LS: Send,
impl<B, LS> Unpin for FirestoreCache<B, LS>where
LS: Unpin,
impl<B, LS> UnsafeUnpin for FirestoreCache<B, LS>where
LS: UnsafeUnpin,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request