pub struct ChunkCache { /* private fields */ }Expand description
Chunk cache manager.
Manages multiple chunked entries, providing efficient lookup and storage of large files split into chunks.
Implementations§
Source§impl ChunkCache
impl ChunkCache
Sourcepub fn get_or_create(
&self,
key: String,
metadata: ChunkMetadata,
) -> Arc<ChunkedEntry>
pub fn get_or_create( &self, key: String, metadata: ChunkMetadata, ) -> Arc<ChunkedEntry>
Gets or creates a chunked entry.
If an entry exists for the key, returns it. Otherwise, creates a new entry with the given metadata.
§Arguments
key- Cache keymetadata- File metadata (used only if creating new entry)
§Examples
let cache = ChunkCache::new(1024 * 1024);
let metadata = ChunkMetadata {
total_size: 10_000_000,
content_type: "video/mp4".to_string(),
etag: None,
last_modified: None,
status: StatusCode::OK,
version: http::Version::HTTP_11,
headers: vec![],
};
let entry = cache.get_or_create("video.mp4".to_string(), metadata);Sourcepub fn stats(&self) -> ChunkCacheStats
pub fn stats(&self) -> ChunkCacheStats
Gets cache statistics.
§Examples
let cache = ChunkCache::new(1024);
let entry = cache.get_or_create("file1".to_string(), metadata);
entry.add_chunk(0, Bytes::from(vec![0u8; 1024]));
let stats = cache.stats();
assert_eq!(stats.total_entries, 1);
assert_eq!(stats.total_chunks, 1);
assert_eq!(stats.total_bytes, 1024);Auto Trait Implementations§
impl Freeze for ChunkCache
impl !RefUnwindSafe for ChunkCache
impl Send for ChunkCache
impl Sync for ChunkCache
impl Unpin for ChunkCache
impl !UnwindSafe for ChunkCache
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
Mutably borrows from an owned value. Read more