pub struct DocCache { /* private fields */ }Expand description
Document cache service
Provides document-specific cache operations, supports crate docs, search results, and item docs.
§Fields
cache: Underlying cache instancettl: TTL configurationstats: Cache statistics
Implementations§
Source§impl DocCache
impl DocCache
Sourcepub fn with_ttl(cache: Arc<dyn Cache>, ttl: DocCacheTtl) -> Self
pub fn with_ttl(cache: Arc<dyn Cache>, ttl: DocCacheTtl) -> Self
Create new document cache (with custom TTL)
§Arguments
cache- cache instancettl- TTL configuration
§Examples
use std::sync::Arc;
use crates_docs::tools::docs::cache::{DocCache, DocCacheTtl};
use crates_docs::cache::memory::MemoryCache;
let cache = Arc::new(MemoryCache::new(1000));
let ttl = DocCacheTtl::with_jitter(
7200, // crate_docs_secs
600, // search_results_secs
3600, // item_docs_secs
0.1, // jitter_ratio
);
let doc_cache = DocCache::with_ttl(cache, ttl);Sourcepub async fn get_crate_docs(
&self,
crate_name: &str,
version: Option<&str>,
) -> Option<Arc<str>>
pub async fn get_crate_docs( &self, crate_name: &str, version: Option<&str>, ) -> Option<Arc<str>>
Sourcepub async fn set_crate_docs(
&self,
crate_name: &str,
version: Option<&str>,
content: String,
) -> Result<()>
pub async fn set_crate_docs( &self, crate_name: &str, version: Option<&str>, content: String, ) -> Result<()>
Sourcepub async fn get_crate_html(
&self,
crate_name: &str,
version: Option<&str>,
) -> Option<Arc<str>>
pub async fn get_crate_html( &self, crate_name: &str, version: Option<&str>, ) -> Option<Arc<str>>
Get cached crate HTML
Returns Arc<str> to avoid unnecessary cloning on cache hits.
The caller can clone if an owned String is needed.
Sourcepub async fn set_crate_html(
&self,
crate_name: &str,
version: Option<&str>,
content: String,
) -> Result<()>
pub async fn set_crate_html( &self, crate_name: &str, version: Option<&str>, content: String, ) -> Result<()>
Sourcepub async fn get_search_results(
&self,
query: &str,
limit: u32,
sort: Option<&str>,
) -> Option<Arc<str>>
pub async fn get_search_results( &self, query: &str, limit: u32, sort: Option<&str>, ) -> Option<Arc<str>>
Sourcepub async fn set_search_results(
&self,
query: &str,
limit: u32,
sort: Option<&str>,
content: String,
) -> Result<()>
pub async fn set_search_results( &self, query: &str, limit: u32, sort: Option<&str>, content: String, ) -> Result<()>
Sourcepub async fn get_item_docs(
&self,
crate_name: &str,
item_path: &str,
version: Option<&str>,
) -> Option<Arc<str>>
pub async fn get_item_docs( &self, crate_name: &str, item_path: &str, version: Option<&str>, ) -> Option<Arc<str>>
Sourcepub async fn set_item_docs(
&self,
crate_name: &str,
item_path: &str,
version: Option<&str>,
content: String,
) -> Result<()>
pub async fn set_item_docs( &self, crate_name: &str, item_path: &str, version: Option<&str>, content: String, ) -> Result<()>
Sourcepub async fn get_item_html(
&self,
crate_name: &str,
item_path: &str,
version: Option<&str>,
) -> Option<Arc<str>>
pub async fn get_item_html( &self, crate_name: &str, item_path: &str, version: Option<&str>, ) -> Option<Arc<str>>
Get cached item HTML
Returns Arc<str> to avoid unnecessary cloning on cache hits.
The caller can clone if an owned String is needed.
Sourcepub async fn set_item_html(
&self,
crate_name: &str,
item_path: &str,
version: Option<&str>,
content: String,
) -> Result<()>
pub async fn set_item_html( &self, crate_name: &str, item_path: &str, version: Option<&str>, content: String, ) -> Result<()>
Sourcepub fn stats(&self) -> &CacheStats
pub fn stats(&self) -> &CacheStats
Get cache statistics
Sourcepub fn ttl(&self) -> &DocCacheTtl
pub fn ttl(&self) -> &DocCacheTtl
Get TTL configuration
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for DocCache
impl !RefUnwindSafe for DocCache
impl Send for DocCache
impl Sync for DocCache
impl Unpin for DocCache
impl UnsafeUnpin for DocCache
impl !UnwindSafe for DocCache
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