From 1b83f4b4b3c76468093eb9c3d57480d2c5c697b9 Mon Sep 17 00:00:00 2001 From: Graham Date: Sun, 13 Jun 2021 12:23:05 +0100 Subject: [PATCH] Add CacheProvider Signed-off-by: Graham --- .../main/kotlin/org/openrs2/game/GameModule.kt | 6 ++++++ .../org/openrs2/game/cache/CacheProvider.kt | 16 ++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 game/src/main/kotlin/org/openrs2/game/cache/CacheProvider.kt diff --git a/game/src/main/kotlin/org/openrs2/game/GameModule.kt b/game/src/main/kotlin/org/openrs2/game/GameModule.kt index ac7c0935..c1b75220 100644 --- a/game/src/main/kotlin/org/openrs2/game/GameModule.kt +++ b/game/src/main/kotlin/org/openrs2/game/GameModule.kt @@ -5,10 +5,12 @@ import com.google.inject.AbstractModule import com.google.inject.Scopes import com.google.inject.multibindings.Multibinder import org.openrs2.buffer.BufferModule +import org.openrs2.cache.Cache import org.openrs2.cache.CacheModule import org.openrs2.cache.Js5MasterIndex import org.openrs2.cache.Store import org.openrs2.conf.ConfigModule +import org.openrs2.game.cache.CacheProvider import org.openrs2.game.cache.Js5MasterIndexProvider import org.openrs2.game.cache.StoreProvider import org.openrs2.game.net.NetworkService @@ -34,5 +36,9 @@ public object GameModule : AbstractModule() { bind(Js5MasterIndex::class.java) .toProvider(Js5MasterIndexProvider::class.java) .`in`(Scopes.SINGLETON) + + bind(Cache::class.java) + .toProvider(CacheProvider::class.java) + .`in`(Scopes.SINGLETON) } } diff --git a/game/src/main/kotlin/org/openrs2/game/cache/CacheProvider.kt b/game/src/main/kotlin/org/openrs2/game/cache/CacheProvider.kt new file mode 100644 index 00000000..c5da0975 --- /dev/null +++ b/game/src/main/kotlin/org/openrs2/game/cache/CacheProvider.kt @@ -0,0 +1,16 @@ +package org.openrs2.game.cache + +import io.netty.buffer.ByteBufAllocator +import org.openrs2.cache.Cache +import org.openrs2.cache.Store +import javax.inject.Inject +import javax.inject.Provider + +public class CacheProvider @Inject constructor( + private val store: Store, + private val alloc: ByteBufAllocator +) : Provider { + override fun get(): Cache { + return Cache.open(store, alloc) + } +}