Skip to main content

FirestoreCache

Struct FirestoreCache 

Source
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

Implementations§

Source§

impl FirestoreCache<FirestoreMemoryCacheBackend, FirestoreMemListenStateStorage>

Source

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?;
Source

pub fn builder( db: &FirestoreDb, ) -> FirestoreCacheBuilder<FirestoreMemoryCacheKind>

Starts building an in-memory cache. Equivalent to FirestoreCache::memory.

Source§

impl FirestoreCache<FirestorePersistentCacheBackend, FirestoreTempFilesListenStateStorage>

Source

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?;
Source

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,

Source

pub async fn new( name: FirestoreCacheName, db: &FirestoreDb, backend: B, listener_storage: LS, ) -> FirestoreResult<Self>
where B: FirestoreCacheBackend + Send + Sync + 'static,

👎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.

Creates a new FirestoreCache with default options for the given name.

§Arguments
  • name: A unique name for this cache instance.
  • db: A reference to the FirestoreDb client.
  • backend: The cache backend implementation.
  • listener_storage: Storage for the listener’s resume state.
§Returns

A FirestoreResult containing the new FirestoreCache.

Source

pub async fn with_options( options: FirestoreCacheOptions, db: &FirestoreDb, backend: B, listener_storage: LS, ) -> FirestoreResult<Self>
where B: FirestoreCacheBackend + Send + Sync + 'static,

👎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.

Creates a new FirestoreCache with the specified options.

§Arguments
  • options: FirestoreCacheOptions to configure the cache.
  • db: A reference to the FirestoreDb client.
  • backend: The cache backend implementation.
  • listener_storage: Storage for the listener’s resume state.
§Returns

A FirestoreResult containing the new FirestoreCache.

Source

pub fn name(&self) -> &FirestoreCacheName

Returns the name of this cache instance.

Source

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.

Source

pub async fn shutdown(&self) -> Result<(), FirestoreError>

Shuts down the Firestore listener and the cache backend.

§Returns

A Result indicating success or failure.

Source

pub fn backend(&self) -> Arc<B> ⓘ

Returns a thread-safe reference-counted pointer to the cache backend.

Source

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<L> LayerExt<L> for L

Source§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more