Cache Lite
A lightweight, cross-platform caching library for Rust with configurable storage and file formatting.
Features
- Cross-platform Support: Works seamlessly on Windows and Linux with platform-specific path configurations
- Configurable Storage: Customize cache paths, file naming formats
- Simple API: Intuitive interface for creating, reading, writing, and deleting cache objects
- Environment Variable Expansion: Automatic expansion of system paths and home directories
- Time-based File Naming: Flexible timestamp formatting in cache filenames
Installation
Add this to your Cargo.toml:
[]
= "0.1.0"
Quick Start
use ;
Configuration
Default Configuration
The library comes with sensible defaults:
Custom Configuration
Create a custom configuration from JSON:
let json_config = r#"
{
"path": {
"windows": "%appdata%/MyApp/Cache",
"linux": "~/.myapp/cache"
},
"format": {
"filename": "{name}_{id}.cache",
"time": "%Y-%m-%d"
}
}"#;
let config = new;
let cache = new;
Per-Object Custom Configuration
Override configuration for individual cache objects:
let custom_config = r#"{"filename": "custom_{name}.cache"}"#;
let cache_obj = cache.create;
API Reference
Cache Manager
The main Cache struct manages multiple cache objects:
Cache Object
Individual cache objects with file operations:
Environment Variables
Windows
The library automatically expands these environment variables in paths:
%temp%,%tmp%- Temporary directory%appdata%- Application data directory%localappdata%- Local application data directory%userprofile%- User profile directory
Linux/Unix
~expands to the user's home directory
File Naming Format
The filename format supports these placeholders:
| Placeholder | Description | Example |
|---|---|---|
{name} |
Cache object name | my_data |
{id} |
Unique numeric ID | 1 |
{time} |
Formatted timestamp | 2026+02+04-14+30+00 |
Examples
Advanced Usage
use ;
use io;
Platform-Specific Behavior
Windows
- Uses Windows environment variable syntax (
%VAR%) - Paths use backslashes by default
- Supports Windows-specific directories
Linux/Unix
- Uses forward slashes for paths
- Supports tilde expansion for home directory
- Follows Unix filesystem conventions
Building from Source
# Clone the repository
# Build the library
# Run tests
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Support
For issues, questions, or suggestions:
- Open an issue on GitHub
- Contact: TaimWay taimway@gmail.com