Skip to content

Request Caching

MrCakeSlayer edited this page Sep 24, 2022 · 1 revision

Lavalink4NET supports request caching of tracks to the Lavalink node.

To use this feature an implementation of ILavalinkCache is required. You can use the Lavalink4NET.MemoryCache NuGet-Package for an example implementation.

Example (using Constructor):

using Lavalink4NET;
using Lavalink4NET.MemoryCache;

var cache = new LavalinkCache(); // <--
var myNode = new LavalinkNode([...], cache);

Example (using DependencyInjection / IoC):

using Lavalink4NET;
using Lavalink4NET.MemoryCache;
using Microsoft.Extensions.DependencyInjection;

var collection = new ServiceCollection()
    .AddSingleton<ILavalinkCache, LavalinkCache>() // <--
    .AddSingleton<IAudioService, LavalinkNode>()
    .AddSingleton<IDiscordClientWrapper, ...>()
    .BuildServiceProvider();