import type { CacheConfig } from '../specs/types.nitro'; import type { MediaPlugin } from './MediaPlugin'; /** * Enable the disk cache for media segments (HLS/DASH) or progressive files. * Caching is opt-in: without this plugin (or player.setCacheEnabled(true)) * loads bypass the cache entirely. * * @example `CachePlugin({ maxSizeBytes: 500 * 1024 * 1024 })` */ export function CachePlugin(config: CacheConfig): MediaPlugin { return { name: 'cache', setup({ engine }): void { engine.setCacheEnabled(true); if (config.maxSizeBytes !== undefined) { engine.setCacheMaxSize(config.maxSizeBytes); } }, teardown(): void {}, }; }