8 releases
new 0.4.0-alpha.6 | Mar 20, 2025 |
---|---|
0.4.0-alpha.4 | Mar 19, 2025 |
0.4.0-alpha.2 | Mar 18, 2025 |
0.3.0-alpha | Mar 18, 2025 |
#4 in #append-only
60 downloads per month
140KB
1.5K
SLoC
SIMD R Drive Extensions
Work in progress.
simd-r-drive-extensions
provides optional utilities for working with Option<T>
and TTL-based caching in SIMD R Drive.
Install
cargo add simd-r-drive-extensions
Usage
Working with Option<T>
use simd_r_drive::DataStore;
use simd_r_drive_extensions::StorageOptionExt;
use std::path::PathBuf;
let storage = DataStore::open(&PathBuf::from("test_store.bin")).unwrap();
// Write Some value
storage.write_option(b"key_with_some_value", Some(&42)).unwrap();
assert_eq!(
storage.read_option::<i32>(b"key_with_some_value").expect("Failed to read key1"),
Some(42)
);
// Write None
storage.write_option::<i32>(b"key_with_none_value", None).unwrap();
assert_eq!(
storage.read_option::<i32>(b"key_with_none_value").expect("Failed to read key2"),
None
);
// Errors on non-existent keys
assert!(storage.read_option::<i32>(b"non_existent_key").is_err());
Working with TTL-based Caching
use simd_r_drive::DataStore;
use simd_r_drive_extensions::StorageCacheExt;
use std::path::PathBuf;
use std::thread::sleep;
use std::time::Duration;
let storage = DataStore::open(&PathBuf::from("test_store.bin")).unwrap();
// Write value with a TTL of 5 seconds
storage.write_with_ttl(b"key_with_ttl", &42, 5).unwrap();
assert_eq!(
storage.read_with_ttl::<i32>(b"key_with_ttl").expect("Failed to read key"),
Some(42)
);
// Wait for TTL to expire
sleep(Duration::from_secs(6));
assert_eq!(
storage.read_with_ttl::<i32>(b"key_with_ttl").expect("Failed to read key"),
None // Key should be expired and removed
);
Implementation Details
- Uses a predefined tombstone marker (
[0xFF, 0xFE]
) to representNone
. - TTL values are stored as a binary prefix before the actual value.
- Values are serialized using bincode.
- ⚠️ Unlike SIMD R Drive, values are non-zero-copy, as they require deserialization.
- TTL-based storage will automatically evict expired values upon read to prevent stale data.
License
Licensed under the Apache-2.0 License.
Dependencies
~1.9–2.7MB
~52K SLoC