AsyncLineCache

Struct AsyncLineCache 

Source
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>) Cache of parsed lines per file path (Arc<Vec>)

§contents: Cache<String, String>

按文件路径缓存完整文件内容(用于兼容旧版 API) Cache of full file content (for legacy API compatibility)

Implementations§

Source§

impl AsyncLineCache

Source

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
Source

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 successfully
  • Ok(None): line number out of range or empty file
  • Err(io_error): I/O error
Source

pub async fn random_line(&self, filename: &str) -> Result<Option<String>>

随机返回文件中任意一行(零分配,极快) Randomly return any line from the file (zero allocation, extremely fast)

Source

pub async fn random_sign_char(&self, filename: &str) -> Result<Option<char>>

随机返回文件中任意一个 Unicode 字符(正确按码点切分) Randomly return any Unicode character from the file (proper grapheme-aware)

Source

pub async fn random_sign(&self, filename: &str) -> Result<Option<String>>

random_sign_char,但返回 String 类型 Same as random_sign_char, but returns String

Source

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)
Source

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
Source

pub async fn invalidate(&self, filename: &str)

手动使指定文件的所有缓存失效 Manually invalidate all caches for a specific file

Source

pub async fn clear(&self)

清空全部缓存(三个缓存全部清除) Clear all caches completely

Source

pub async fn clear_cache(&self)

👎Deprecated since 0.2.0: 请使用 clear() 替代 | use clear() instead

兼容旧版方法名(已废弃,仅为平滑升级保留) Legacy method name (deprecated, kept for smooth migration)

Trait Implementations§

Source§

impl Clone for AsyncLineCache

Source§

fn clone(&self) -> AsyncLineCache

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for AsyncLineCache

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for AsyncLineCache

为方便使用提供 Default 实现 Provide Default implementation for convenience

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V