pub struct ArtifactCache { /* private fields */ }Expand description
Global artifact cache
Provides persistent caching of compiled dynamic libraries using SHA256 content-addressed storage. The cache is shared across all REPL sessions and persists across restarts.
§Cache Key Algorithm (ODD-0026)
SHA256(
source_code +
dependencies +
optimization_level +
source_map_config
)§Directory Structure
~/.cache/oxur/artifacts/
├── index.json # Cache index
├── <sha256-1>/
│ ├── lib.so # Compiled artifact (Linux)
│ └── metadata.json # Entry metadata
├── <sha256-2>/
│ ├── lib.dylib # Compiled artifact (macOS)
│ └── metadata.json
└── ...§Examples
use oxur_repl::cache::ArtifactCache;
let mut cache = ArtifactCache::new()?;
// Generate cache key from source
let key = cache.generate_key("(+ 1 2)", &[], 0, "default");
// Check if artifact exists
if let Some(path) = cache.get(&key)? {
println!("Cache hit: {:?}", path);
} else {
println!("Cache miss, need to compile");
}Implementations§
Source§impl ArtifactCache
impl ArtifactCache
Sourcepub fn new() -> Result<Self, CacheError>
pub fn new() -> Result<Self, CacheError>
Create or open the global artifact cache
Uses platform-specific cache directory:
- Linux:
~/.cache/oxur/artifacts/ - macOS:
~/Library/Caches/oxur/artifacts/ - Windows:
%LOCALAPPDATA%\oxur\artifacts\
Can be overridden with OXUR_CACHE_DIR environment variable.
§Errors
Returns error if cache directory cannot be created or index cannot be loaded
Sourcepub fn with_directory(cache_dir: impl AsRef<Path>) -> Result<Self, CacheError>
pub fn with_directory(cache_dir: impl AsRef<Path>) -> Result<Self, CacheError>
Sourcepub fn generate_key(
&self,
source: impl AsRef<str>,
dependencies: &[(&str, &str)],
opt_level: u8,
source_map_config: impl AsRef<str>,
) -> String
pub fn generate_key( &self, source: impl AsRef<str>, dependencies: &[(&str, &str)], opt_level: u8, source_map_config: impl AsRef<str>, ) -> String
Sourcepub fn insert(
&mut self,
key: impl AsRef<str>,
artifact_path: &Path,
) -> Result<PathBuf, CacheError>
pub fn insert( &mut self, key: impl AsRef<str>, artifact_path: &Path, ) -> Result<PathBuf, CacheError>
Sourcepub fn clear(&mut self) -> Result<(), CacheError>
pub fn clear(&mut self) -> Result<(), CacheError>
Clear all cached artifacts
Removes all artifacts from cache directory and resets index.
Sourcepub fn stats(&self) -> (usize, u64)
pub fn stats(&self) -> (usize, u64)
Get cache statistics
Returns (entry_count, total_size_bytes)
Sourcepub fn detailed_stats(&self) -> CacheStats
pub fn detailed_stats(&self) -> CacheStats
Get detailed cache statistics
Returns comprehensive statistics including oldest/newest entries
Sourcepub fn evict_lru(
&mut self,
max_size_bytes: Option<u64>,
) -> Result<usize, CacheError>
pub fn evict_lru( &mut self, max_size_bytes: Option<u64>, ) -> Result<usize, CacheError>
Evict least recently used cache entries
Removes oldest entries until total cache size is below the limit.
Default limit is 1GB. Can be configured via OXUR_CACHE_MAX_SIZE_MB environment variable.
§Arguments
max_size_bytes- Maximum allowed cache size in bytes. If None, uses default (1GB)
§Returns
Number of entries evicted
§Examples
use oxur_repl::cache::ArtifactCache;
let mut cache = ArtifactCache::new()?;
let evicted = cache.evict_lru(Some(100 * 1024 * 1024))?; // Limit to 100MB
println!("Evicted {} cache entries", evicted);Sourcepub fn total_size_bytes(&self) -> u64
pub fn total_size_bytes(&self) -> u64
Get total cache size in bytes
Sourcepub fn check_and_evict(&mut self) -> Result<usize, CacheError>
pub fn check_and_evict(&mut self) -> Result<usize, CacheError>
Check if cache is over size limit and evict if needed
This is automatically called after insert() operations.
Can also be called manually for periodic cleanup.
§Returns
Number of entries evicted
Trait Implementations§
Source§impl Clone for ArtifactCache
impl Clone for ArtifactCache
Source§fn clone(&self) -> ArtifactCache
fn clone(&self) -> ArtifactCache
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for ArtifactCache
impl RefUnwindSafe for ArtifactCache
impl Send for ArtifactCache
impl Sync for ArtifactCache
impl Unpin for ArtifactCache
impl UnwindSafe for ArtifactCache
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi Quirk value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);