pub struct AsyncLineCache {
pub lines: Cache<String, Arc<Vec<String>>>,
pub contents: Cache<String, String>,
/* private fields */
}Expand description
工业级异步行缓存核心结构体 Industrial-grade asynchronous line cache core structure
Fields§
§lines: Cache<String, Arc<Vec<String>>>按文件路径缓存解析后的行向量(Arc<Vec
contents: Cache<String, String>按文件路径缓存完整文件内容(用于兼容旧版 API) Cache of full file content (for legacy API compatibility)
Implementations§
Source§impl AsyncLineCache
impl AsyncLineCache
Sourcepub fn new() -> Self
pub fn new() -> Self
创建一个推荐用于生产环境的实例 Create a new instance with production-recommended configuration
- 总缓存大小限制为系统内存的 85%
- 行缓存与内容缓存各占一半
- 使用精确的内存权重计算,防止 OOM
- Total cache size limited to 85% of system memory
- Lines cache and contents cache each take half
- Precise memory weighting to prevent OOM
Sourcepub async fn get_line(
&self,
filename: &str,
lineno: usize,
) -> Result<Option<String>>
pub async fn get_line( &self, filename: &str, lineno: usize, ) -> Result<Option<String>>
获取指定文件的第 lineno 行(从 1 开始计数)
Get the lineno-th line of the file (1-based indexing)
返回值:
Ok(Some(line)):成功获取行Ok(None):行号超出范围或空文件Err(io_error):IO 错误 Return value:Ok(Some(line)): line retrieved successfullyOk(None): line number out of range or empty fileErr(io_error): I/O error
Sourcepub async fn random_line(&self, filename: &str) -> Result<Option<String>>
pub async fn random_line(&self, filename: &str) -> Result<Option<String>>
随机返回文件中任意一行(零分配,极快) Randomly return any line from the file (zero allocation, extremely fast)
Sourcepub async fn random_sign_char(&self, filename: &str) -> Result<Option<char>>
pub async fn random_sign_char(&self, filename: &str) -> Result<Option<char>>
随机返回文件中任意一个 Unicode 字符(正确按码点切分) Randomly return any Unicode character from the file (proper grapheme-aware)
Sourcepub async fn random_sign(&self, filename: &str) -> Result<Option<String>>
pub async fn random_sign(&self, filename: &str) -> Result<Option<String>>
同 random_sign_char,但返回 String 类型
Same as random_sign_char, but returns String
Sourcepub async fn get_lines(&self, filename: &str) -> Result<Option<Vec<String>>>
pub async fn get_lines(&self, filename: &str) -> Result<Option<Vec<String>>>
获取文件全部行(完全兼容旧版 DashMap 实现) Get all lines of the file (fully compatible with legacy DashMap implementation)
- 空文件返回
None(与 Python linecache 行为一致) - Empty file returns
None(same as Python linecache)
Sourcepub async fn get_content(&self, filename: &str) -> Result<Option<String>>
pub async fn get_content(&self, filename: &str) -> Result<Option<String>>
获取文件完整内容(兼容旧版 API) Get full file content (compatible with legacy API)
- 文件不存在返回
None - File not found returns
None
Sourcepub async fn invalidate(&self, filename: &str)
pub async fn invalidate(&self, filename: &str)
手动使指定文件的所有缓存失效 Manually invalidate all caches for a specific file
Sourcepub async fn clear_cache(&self)
👎Deprecated since 0.2.0: 请使用 clear() 替代 | use clear() instead
pub async fn clear_cache(&self)
兼容旧版方法名(已废弃,仅为平滑升级保留) Legacy method name (deprecated, kept for smooth migration)
Trait Implementations§
Source§impl Clone for AsyncLineCache
impl Clone for AsyncLineCache
Source§fn clone(&self) -> AsyncLineCache
fn clone(&self) -> AsyncLineCache
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more