Expand description
§Rust Cache Library
A lightweight, cross-platform caching library for Rust applications. Provides configurable cache storage, lifecycle management, and file formatting.
§Features
- Cross-platform: Automatic path handling for Windows and Linux
- Configurable: JSON-based configuration with runtime overrides
- Simple API: Easy-to-use interface for cache operations
- File-based: Persistent cache storage on disk
§Quick Start
use cache_lite::{Cache, CacheConfig};
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create cache with default configuration
let config = CacheConfig::default();
let mut cache = Cache::new(config)?;
// Create a new cache object
let cache_obj = cache.create("my_cache", None).unwrap();
// Write data to cache
cache_obj.write_string("Cached data").unwrap();
// Read data from cache
let data = cache_obj.get_string().unwrap();
assert_eq!(data, "Cached data");
cache_obj.delete()?;
Ok(())
}§Configuration
The library supports JSON configuration for customizing cache behavior:
{
"path": {
"windows": "%temp%/MyApp/Cache",
"linux": "/tmp/myapp/cache"
},
"format": {
"filename": "{name}_{time}.cache",
"time": "%Y%m%d_%H%M%S"
}
}§Error Handling
The library provides a comprehensive error type CacheError for handling
various failure scenarios including I/O errors, invalid configurations,
permission issues, and more.
Structs§
- Cache
- Main cache manager handling multiple cache objects
- Cache
Config - Main configuration structure for cache behavior
- Cache
Format Config - File naming format configuration
- Cache
Object - Represents an individual cache object with file operations
- Cache
Path Config - Platform-specific path configuration
Enums§
- Cache
Error - Cache library error types
Type Aliases§
- Cache
Result - Result type alias for cache operations