Skip to content

Commit

Permalink
fix: missing redis import
Browse files Browse the repository at this point in the history
  • Loading branch information
netomi committed Feb 26, 2024
1 parent ceb1743 commit da03458
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 38 deletions.
36 changes: 0 additions & 36 deletions otterdog/providers/github/cache/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,44 +9,8 @@
from abc import ABC, abstractmethod

from aiohttp_client_cache import CacheBackend
from redis.asyncio.client import Redis


class CacheStrategy(ABC):
@abstractmethod
def get_cache_backend(self) -> CacheBackend: ...


_AIOHTTP_CACHE_DIR = ".cache/async_http"


class _FileCache(CacheStrategy):
def __init__(self, cache_dir: str):
self._cache_dir = cache_dir

def get_cache_backend(self) -> CacheBackend:
from aiohttp_client_cache.backends import FileBackend

return FileBackend(
cache_name=self._cache_dir,
use_temp=False,
)


class _RedisCache(CacheStrategy):
def __init__(self, redis_uri: str, connection: Redis | None):
self._redis_uri = redis_uri
self._connection = connection

def get_cache_backend(self) -> CacheBackend:
from aiohttp_client_cache.backends import RedisBackend

return RedisBackend(address=self._redis_uri, connection=self._connection)


def file_cache(cache_dir: str = _AIOHTTP_CACHE_DIR) -> CacheStrategy:
return _FileCache(cache_dir)


def redis_cache(uri: str, connection: Redis | None = None) -> CacheStrategy:
return _RedisCache(uri, connection)
30 changes: 30 additions & 0 deletions otterdog/providers/github/cache/file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# *******************************************************************************
# Copyright (c) 2024 Eclipse Foundation and others.
# This program and the accompanying materials are made available
# under the terms of the Eclipse Public License 2.0
# which is available at http://www.eclipse.org/legal/epl-v20.html
# SPDX-License-Identifier: EPL-2.0
# *******************************************************************************

from aiohttp_client_cache import CacheBackend

from otterdog.providers.github.cache import CacheStrategy

_AIOHTTP_CACHE_DIR = ".cache/async_http"


def file_cache(cache_dir: str = _AIOHTTP_CACHE_DIR) -> CacheStrategy:
return _FileCache(cache_dir)


class _FileCache(CacheStrategy):
def __init__(self, cache_dir: str):
self._cache_dir = cache_dir

def get_cache_backend(self) -> CacheBackend:
from aiohttp_client_cache.backends import FileBackend

return FileBackend(
cache_name=self._cache_dir,
use_temp=False,
)
27 changes: 27 additions & 0 deletions otterdog/providers/github/cache/redis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# *******************************************************************************
# Copyright (c) 2024 Eclipse Foundation and others.
# This program and the accompanying materials are made available
# under the terms of the Eclipse Public License 2.0
# which is available at http://www.eclipse.org/legal/epl-v20.html
# SPDX-License-Identifier: EPL-2.0
# *******************************************************************************

from aiohttp_client_cache import CacheBackend
from redis.asyncio.client import Redis

from otterdog.providers.github.cache import CacheStrategy


def redis_cache(uri: str, connection: Redis | None = None) -> CacheStrategy:
return _RedisCache(uri, connection)


class _RedisCache(CacheStrategy):
def __init__(self, redis_uri: str, connection: Redis | None):
self._redis_uri = redis_uri
self._connection = connection

def get_cache_backend(self) -> CacheBackend:
from aiohttp_client_cache.backends import RedisBackend

return RedisBackend(address=self._redis_uri, connection=self._connection)
3 changes: 2 additions & 1 deletion otterdog/providers/github/rest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
from functools import cached_property

from otterdog.providers.github.auth import AuthStrategy
from otterdog.providers.github.cache import CacheStrategy, file_cache
from otterdog.providers.github.cache import CacheStrategy
from otterdog.providers.github.cache.file import file_cache

from .requester import Requester

Expand Down
2 changes: 1 addition & 1 deletion otterdog/webapp/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

from otterdog.config import OtterdogConfig
from otterdog.providers.github.auth import app_auth, token_auth
from otterdog.providers.github.cache import redis_cache
from otterdog.providers.github.cache.redis import redis_cache
from otterdog.providers.github.graphql import GraphQLClient
from otterdog.providers.github.rest import RestApi

Expand Down

0 comments on commit da03458

Please sign in to comment.