pub struct DocService { /* private fields */ }Expand description
文档服务
提供 HTTP 客户端(带自动重试)、缓存和文档缓存的集中管理。
§字段
client: 带重试中间件的 HTTP 客户端(共享引用以实现连接池复用)cache: 通用缓存实例doc_cache: 文档专用缓存
Implementations§
Source§impl DocService
impl DocService
Sourcepub fn new(cache: Arc<dyn Cache>) -> Result<Self>
pub fn new(cache: Arc<dyn Cache>) -> Result<Self>
创建新的文档服务(使用默认 TTL)
§参数
cache- 缓存实例
§错误
如果 HTTP 客户端创建失败,返回错误
§示例
use std::sync::Arc;
use crates_docs::tools::docs::DocService;
use crates_docs::cache::memory::MemoryCache;
let cache = Arc::new(MemoryCache::new(1000));
let service = DocService::new(cache).expect("Failed to create DocService");§Note
This method uses the global HTTP client singleton for connection pool reuse.
Make sure to call init_global_http_client() during server initialization
for optimal performance.
Sourcepub fn with_config(
cache: Arc<dyn Cache>,
cache_config: &CacheConfig,
) -> Result<Self>
pub fn with_config( cache: Arc<dyn Cache>, cache_config: &CacheConfig, ) -> Result<Self>
Sourcepub fn with_full_config(
cache: Arc<dyn Cache>,
cache_config: &CacheConfig,
_perf_config: &PerformanceConfig,
) -> Result<Self>
pub fn with_full_config( cache: Arc<dyn Cache>, cache_config: &CacheConfig, _perf_config: &PerformanceConfig, ) -> Result<Self>
创建新的文档服务(使用完整配置)
§参数
cache- 缓存实例cache_config- 缓存配置perf_config- 性能配置(仅用于初始化全局 HTTP 客户端,如果尚未初始化)
§错误
如果 HTTP 客户端创建失败,返回错误
§Note
This method uses the global HTTP client singleton for connection pool reuse.
The perf_config is used only if the global client hasn’t been initialized yet.
For consistent configuration, call init_global_http_client() during server startup.
Sourcepub fn client(&self) -> &ClientWithMiddleware
pub fn client(&self) -> &ClientWithMiddleware
获取 HTTP 客户端(带重试中间件)
Trait Implementations§
Auto Trait Implementations§
impl Freeze for DocService
impl !RefUnwindSafe for DocService
impl Send for DocService
impl Sync for DocService
impl Unpin for DocService
impl UnsafeUnpin for DocService
impl !UnwindSafe for DocService
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