Skip to content

[FR] Expose tile cache configuration (SlideOpenOptions / GlobalCacheManager) through the C API and Rust bindings #58

Description

@AzHicham

Summary

The internal tile cache (ITileCache / LRUTileCache / GlobalCacheManager, and the enable_caching / cache_size_mb fields on SlideOpenOptions) is fully wired into the Python bindings (src/python/fastslide.cpp), but is unreachable from the C API and therefore from the Rust bindings (fastslide-sys / fastslide crates).

Current behavior (traced from Rust)

  • SlideReader::open(path) (rust/fastslide/src/reader.rs) calls fastslide_create_reader(path).
  • That calls ReaderRegistry::CreateReader(filename, cache = nullptr) (include/fastslide/runtime/reader_registry.h), where cache always defaults to nullptr since no C API entry point exposes it.
  • Format factories only call reader->SetCache(cache) when cache is non-null, so SlideReader::cache_ stays nullptr and IsCacheEnabled() returns false.
  • As a result, CachedTileExecutor::ReadWithCache skips all Get/Put calls, and every tile is decoded from disk on every read — including repeated/adjacent reads that fall within the same native tile grid cell (e.g. two 256×256 ReadRegion calls inside the same 512×512 SVS tile).
  • SlideOpenOptions.enable_caching / cache_size_mb are declared in include/fastslide/slide_options.h but are never constructed or read anywhere in src/ — dead code with respect to this call path.
  • GlobalCacheManager::Instance() (1 GiB default LRUTileCache) is likewise never invoked outside the Python bindings.

This means C/Rust consumers get none of the decode-reuse benefit that the cache architecture (and the Python bindings) already provide — comparable to running OpenSlide with tile caching disabled.

Request

Expose a way to enable/configure the internal tile cache from the C API, so Rust (and other C API consumers) can opt in without reimplementing tile-grid-aware caching at the application layer. For example:

  • A C API function such as fastslide_reader_set_cache(reader, capacity_bytes) (or fastslide_create_reader_with_cache(path, capacity_bytes)), mirroring what examples/cache_example.cpp already does in C++ (LRUTileCache::Create(bytes) + reader->SetCache(cache)).
  • Optionally, wire SlideOpenOptions.enable_caching / cache_size_mb through to this path so the struct isn't dead code, or remove it if superseded by an explicit cache-injection API.
  • Surface the equivalent call in fastslide-sys/fastslide Rust crates (e.g. SlideReader::open_with_cache(path, capacity_bytes)).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions