2023-03-14 01:27:22 +00:00
|
|
|
from core.base_service import BaseService
|
2023-05-02 16:16:14 +00:00
|
|
|
from core.services.game.cache import GameCacheForStrategy, GameCacheForMaterial, GameCacheForLightCone
|
2022-07-26 10:07:31 +00:00
|
|
|
|
2023-05-02 16:16:14 +00:00
|
|
|
__all__ = "GameCacheService"
|
2022-07-26 10:07:31 +00:00
|
|
|
|
2023-03-14 01:27:22 +00:00
|
|
|
|
2023-05-02 16:16:14 +00:00
|
|
|
class GameCacheService(BaseService):
|
|
|
|
def __init__(
|
2023-05-03 12:54:26 +00:00
|
|
|
self,
|
|
|
|
strategy_cache: GameCacheForStrategy,
|
|
|
|
material_cache: GameCacheForMaterial,
|
|
|
|
light_cone_cache: GameCacheForLightCone,
|
2023-05-02 16:16:14 +00:00
|
|
|
):
|
|
|
|
self.strategy_cache = strategy_cache
|
|
|
|
self.material_cache = material_cache
|
|
|
|
self.light_cone_cache = light_cone_cache
|
2022-07-26 10:07:31 +00:00
|
|
|
|
2023-04-26 08:48:05 +00:00
|
|
|
async def get_strategy_cache(self, character_name: str) -> str:
|
2023-05-02 16:16:14 +00:00
|
|
|
cache = await self.strategy_cache.get_file(character_name)
|
2023-04-26 08:48:05 +00:00
|
|
|
if cache is not None:
|
2023-05-03 12:54:26 +00:00
|
|
|
return cache.decode("utf-8")
|
2022-07-26 10:07:31 +00:00
|
|
|
|
2023-04-26 08:48:05 +00:00
|
|
|
async def set_strategy_cache(self, character_name: str, file: str) -> None:
|
2023-05-02 16:16:14 +00:00
|
|
|
await self.strategy_cache.set_file(character_name, file)
|
|
|
|
|
|
|
|
async def get_material_cache(self, character_name: str) -> str:
|
|
|
|
cache = await self.material_cache.get_file(character_name)
|
|
|
|
if cache is not None:
|
2023-05-03 12:54:26 +00:00
|
|
|
return cache.decode("utf-8")
|
2023-05-02 16:16:14 +00:00
|
|
|
|
|
|
|
async def set_material_cache(self, character_name: str, file: str) -> None:
|
|
|
|
await self.material_cache.set_file(character_name, file)
|
|
|
|
|
|
|
|
async def get_light_cone_cache(self, light_cone_name: str) -> str:
|
|
|
|
cache = await self.light_cone_cache.get_file(light_cone_name)
|
|
|
|
if cache is not None:
|
2023-05-03 12:54:26 +00:00
|
|
|
return cache.decode("utf-8")
|
2023-05-02 16:16:14 +00:00
|
|
|
|
|
|
|
async def set_light_cone_cache(self, light_cone_name: str, file: str) -> None:
|
|
|
|
await self.light_cone_cache.set_file(light_cone_name, file)
|