Skip to main content

Crate cache_lite

Crate cache_lite 

Source
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};
 
// 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");

§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
CacheConfig
Main configuration structure for cache behavior
CacheFormatConfig
File naming format configuration
CacheObject
Represents an individual cache object with file operations
CachePathConfig
Platform-specific path configuration

Enums§

CacheError
Cache library error types

Type Aliases§

CacheResult
Result type alias for cache operations