pub struct CachingClient<T> { /* private fields */ }
Expand description
A client that caches response data using the given cache implementation. Can be used without an underlying client to be used as a read-only cache.
Implementations§
Source§impl<T: Cache> CachingClient<T>
impl<T: Cache> CachingClient<T>
Sourcepub fn new(client: Option<Client>, cache: T) -> Self
pub fn new(client: Option<Client>, cache: T) -> Self
Creates a new caching client from the given client and cache implementation. If no client is given, the client will be in offline or read-only mode, meaning it will only be able to return things that are already in the cache.
Sourcepub fn is_readonly(&self) -> bool
pub fn is_readonly(&self) -> bool
Returns whether or not the client is in read-only mode.
Sourcepub async fn list_all_versions(
&self,
package: &PackageRef,
) -> Result<Vec<VersionInfo>, Error>
pub async fn list_all_versions( &self, package: &PackageRef, ) -> Result<Vec<VersionInfo>, Error>
Returns a list of all package VersionInfo
s available for the given package. This will
always fail if no client was provided.
Sourcepub async fn get_release(
&self,
package: &PackageRef,
version: &Version,
) -> Result<Release, Error>
pub async fn get_release( &self, package: &PackageRef, version: &Version, ) -> Result<Release, Error>
Returns a Release
for the given package version.
Sourcepub async fn get_content(
&self,
package: &PackageRef,
release: &Release,
) -> Result<ContentStream, Error>
pub async fn get_content( &self, package: &PackageRef, release: &Release, ) -> Result<ContentStream, Error>
Returns a ContentStream
of content chunks. If the data is in the cache, it will be returned,
otherwise it will be fetched from an upstream registry and then cached. This is the same as
Client::stream_content
but named differently to avoid confusion when trying to use this
as a normal Client
.
Sourcepub fn client(&self) -> Result<&Client, Error>
pub fn client(&self) -> Result<&Client, Error>
Returns a reference to the underlying client. Returns an error if the client is in read-only mode.
Please note that using the client directly will bypass the cache.
Sourcepub fn into_client(self) -> Result<Client, Error>
pub fn into_client(self) -> Result<Client, Error>
Consumes the caching client and returns the underlying client. Returns an error if the client is in read-only mode.
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for CachingClient<T>
impl<T> !RefUnwindSafe for CachingClient<T>
impl<T> Send for CachingClient<T>
impl<T> Sync for CachingClient<T>
impl<T> Unpin for CachingClient<T>
impl<T> !UnwindSafe for CachingClient<T>
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>
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>
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