Table of Contents

Class FileCache

Namespace
VAST.File
Assembly
VAST.File.dll

Provides caching functionality for media sources and streams, automatically disposing expired entries after a configurable timeout period. Used to optimize repeated access to the same media files.

public class FileCache : IDisposable
Inheritance
FileCache
Implements
Inherited Members

Constructors

FileCache()

Initializes a new instance of the FileCache class.

public FileCache()

Methods

Add(string, Stream)

Adds or replaces a stream in the cache for the specified file path.

public void Add(string filePath, Stream stream)

Parameters

filePath string

The file path to use as the cache key.

stream Stream

The stream to cache.

Add(string, IMediaSource)

Adds or replaces a media source in the cache for the specified file path.

public void Add(string filePath, IMediaSource source)

Parameters

filePath string

The file path to use as the cache key.

source IMediaSource

The media source to cache.

Dispose()

Releases all cached media sources and streams, clearing the cache.

public void Dispose()

GetSource(string)

Gets a cached media source for the specified file path, opening and caching it if not already cached.

public IMediaSource GetSource(string filePath)

Parameters

filePath string

The file path to retrieve or open.

Returns

IMediaSource

The cached or newly opened media source, or null if the file type is unsupported.

Exceptions

ArgumentException

Thrown when the file fails to open.

GetStream(string)

Gets a cached stream for the specified file path.

public Stream GetStream(string filePath)

Parameters

filePath string

The file path to retrieve.

Returns

Stream

The cached stream, or null if no stream is cached for the specified path.

Update()

Performs cache maintenance by disposing entries that have expired based on the timeout period. Should be called periodically to clean up unused cached files.

public void Update()

UpdateUseState(string)

Updates the last used timestamp for the specified file path, preventing it from expiring.

public void UpdateUseState(string filePath)

Parameters

filePath string

The file path of the cached entry to update.