pub struct TileService<S: SlideSource> { /* private fields */ }Expand description
Service for generating and caching tiles.
The TileService orchestrates the full tile pipeline:
- Validates request parameters
- Checks the tile cache for existing results
- Fetches the slide from the registry
- Reads raw tile data from the slide
- Decodes and re-encodes at the requested quality
- Caches and returns the result
§Type Parameters
S- The slide source type (e.g., S3-based source)
§Example
use wsi_streamer::tile::{TileService, TileRequest};
use wsi_streamer::slide::SlideRegistry;
// Create registry and service
let registry = SlideRegistry::new(source);
let service = TileService::new(registry);
// Request a tile
let request = TileRequest::new("slides/sample.svs", 0, 1, 2);
let response = service.get_tile(request).await?;
println!("Tile size: {} bytes, cache hit: {}", response.data.len(), response.cache_hit);Implementations§
Source§impl<S: SlideSource> TileService<S>
impl<S: SlideSource> TileService<S>
Sourcepub fn new(registry: SlideRegistry<S>) -> Self
pub fn new(registry: SlideRegistry<S>) -> Self
Create a new tile service with default cache settings.
Uses default tile cache capacity (100MB).
Create a new tile service with a shared registry.
This allows multiple services or components to share the same registry.
Sourcepub fn with_cache_capacity(
registry: SlideRegistry<S>,
cache_capacity: usize,
) -> Self
pub fn with_cache_capacity( registry: SlideRegistry<S>, cache_capacity: usize, ) -> Self
Create a new tile service with custom cache capacity.
§Arguments
registry- The slide registrycache_capacity- Maximum tile cache size in bytes
Sourcepub async fn get_tile(
&self,
request: TileRequest,
) -> Result<TileResponse, TileError>
pub async fn get_tile( &self, request: TileRequest, ) -> Result<TileResponse, TileError>
Get a tile, using cache when available.
This is the main entry point for tile requests. It:
- Validates the request parameters
- Checks the cache for an existing tile
- If not cached, fetches from the slide and encodes
- Caches and returns the result
§Errors
Returns an error if:
- The slide cannot be found or opened
- The level is out of range
- The tile coordinates are out of bounds
- The tile data cannot be decoded or encoded
Sourcepub async fn generate_tile(
&self,
request: &TileRequest,
quality: u8,
) -> Result<Bytes, TileError>
pub async fn generate_tile( &self, request: &TileRequest, quality: u8, ) -> Result<Bytes, TileError>
Generate a tile without caching.
This is useful for one-off requests or when you want to bypass the cache.
Sourcepub async fn cache_stats(&self) -> (usize, usize, usize)
pub async fn cache_stats(&self) -> (usize, usize, usize)
Get tile cache statistics.
Returns (current_size, capacity, entry_count).
Sourcepub async fn clear_cache(&self)
pub async fn clear_cache(&self)
Clear the tile cache.
Sourcepub async fn invalidate_slide(&self, _slide_id: &str)
pub async fn invalidate_slide(&self, _slide_id: &str)
Invalidate cached tiles for a specific slide.
This removes all cached tiles for the given slide from the tile cache. Note: This is O(n) where n is the number of cached tiles.
Sourcepub fn registry(&self) -> &Arc<SlideRegistry<S>>
pub fn registry(&self) -> &Arc<SlideRegistry<S>>
Get a reference to the underlying registry.
Sourcepub async fn generate_thumbnail(
&self,
slide_id: &str,
max_dimension: u32,
quality: u8,
) -> Result<TileResponse, TileError>
pub async fn generate_thumbnail( &self, slide_id: &str, max_dimension: u32, quality: u8, ) -> Result<TileResponse, TileError>
Generate a thumbnail for a slide.
This finds the lowest resolution level that fits within the requested max dimension and returns a tile or composited image.
§Arguments
slide_id- The slide identifiermax_dimension- Maximum width or height for the thumbnailquality- JPEG quality (1-100)
§Returns
A JPEG-encoded thumbnail image.
Auto Trait Implementations§
impl<S> !Freeze for TileService<S>
impl<S> !RefUnwindSafe for TileService<S>
impl<S> Send for TileService<S>
impl<S> Sync for TileService<S>
impl<S> Unpin for TileService<S>
impl<S> !UnwindSafe for TileService<S>
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more