package com.avairebot.orion.scheduler;

import com.avairebot.orion.Orion;
import com.avairebot.orion.cache.CacheType;
import com.avairebot.orion.cache.adapters.MemoryAdapter;
import com.avairebot.orion.contracts.scheduler.Job;

public class GarbageCollectorJob extends Job {

    public GarbageCollectorJob(Orion orion) {
        super(orion);
    }

    @Override
    public void run() {
        MemoryAdapter adapter = (MemoryAdapter) orion.getCache().getAdapter(CacheType.MEMORY);

        for (String key : adapter.getCacheKeys()) {
            if (!adapter.has(key)) {
                adapter.forget(key);
            }
        }
    }
}

@@ -67,16 +67,115 @@
 .Orion;%0A
+import com.avairebot.orion.audio.AudioHandler;%0Aimport com.avairebot.orion.audio.GuildMusicManager;%0A
 import c
@@ -320,16 +320,39 @@
 r.Job;%0A%0A
+import java.util.Map;%0A%0A
 public c
@@ -612,126 +612,818 @@
     
-for (String key : adapter.getCacheKeys()) %7B%0A            if (!adapter.has(key)) %7B%0A                adapter.forget(key
+adapter.getCacheKeys().removeIf(key -%3E !adapter.has(key));%0A%0A        for (Map.Entry%3CLong, GuildMusicManager%3E entry : AudioHandler.MUSIC_MANAGER.entrySet()) %7B%0A            if (entry.getValue() == null) %7B%0A                AudioHandler.MUSIC_MANAGER.remove(entry.getKey());%0A                continue;%0A            %7D%0A%0A            if (entry.getValue().getLastActiveMessage() == null) %7B%0A                continue;%0A            %7D%0A%0A            if (entry.getValue().getLastActiveMessage().getGuild().getAudioManager().isConnected()) %7B%0A                continue;%0A            %7D%0A%0A            if (!adapter.has(getCacheFingerprint(entry.getKey()))) %7B%0A                adapter.put(getCacheFingerprint(entry.getKey()), 0, 120);%0A                continue;%0A            %7D%0A%0A            adapter.forget(getCacheFingerprint(entry.getKey())
 );%0A
+%0A
     
@@ -1434,19 +1434,189 @@
     
-%7D%0A        %7D
+AudioHandler.MUSIC_MANAGER.remove(entry.getKey());%0A        %7D%0A    %7D%0A%0A    private String getCacheFingerprint(Long guildId) %7B%0A        return %22garbage-collector.music-queue.%22 + guildId;
 %0A   

Add music manager cleanup to the garbage collector