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 {
crate_docs_secs: 7200,
search_results_secs: 600,
item_docs_secs: 3600,
jitter_ratio: 0.1,
};
let doc_cache = DocCache::with_ttl(cache, ttl);Sourcepub async fn get_crate_docs(
&self,
crate_name: &str,
version: Option<&str>,
) -> Option<String>
pub async fn get_crate_docs( &self, crate_name: &str, version: Option<&str>, ) -> Option<String>
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 set_search_results(
&self,
query: &str,
limit: u32,
content: String,
) -> Result<()>
pub async fn set_search_results( &self, query: &str, limit: u32, content: String, ) -> Result<()>
Sourcepub async fn get_item_docs(
&self,
crate_name: &str,
item_path: &str,
version: Option<&str>,
) -> Option<String>
pub async fn get_item_docs( &self, crate_name: &str, item_path: &str, version: Option<&str>, ) -> Option<String>
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 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