Skip to content

Commit

Permalink
ci: add caching ttl config by environment vars
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandreSenpai committed Apr 6, 2024
1 parent 1c503ca commit f9ec4b5
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 14 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/dev-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@ jobs:
ENMA_CACHING_MANGADEX_PAGINATE_TTL_IN_SECONDS='0' \
ENMA_CACHING_MANGADEX_SEARCH_TTL_IN_SECONDS='0' \
ENMA_CACHING_MANGADEX_GET_TTL_IN_SECONDS='0' \
ENMA_CACHING_MANGADEX_FETCH_SYMBOLIC_LINK_TTL_IN_SECONDS='0' \
ENMA_CACHING_MANGADEX_FETCH_SYMBOLIC_LINK_TTL_IN_SECONDS='0' \
ENMA_CACHING_NHENTAI_PAGINATE_TTL_IN_SECONDS='0' \
ENMA_CACHING_NHENTAI_SEARCH_TTL_IN_SECONDS='0' \
ENMA_CACHING_NHENTAI_GET_TTL_IN_SECONDS='0' \
ENMA_CACHING_NHENTAI_FETCH_SYMBOLIC_LINK_TTL_IN_SECONDS='0' \
ENMA_CACHING_NHENTAI_AUTHOR_TTL_IN_SECONDS='0' \
ENMA_CACHING_NHENTAI_FETCH_SYMBOLIC_LINK_TTL_IN_SECONDS='0' \
ENMA_CACHING_NHENTAI_AUTHOR_TTL_IN_SECONDS='0' \
ENMA_CACHING_MANGANATO_PAGINATE_TTL_IN_SECONDS='0' \
ENMA_CACHING_MANGANATO_SEARCH_TTL_IN_SECONDS='0' \
ENMA_CACHING_MANGANATO_GET_TTL_IN_SECONDS='0' \
ENMA_CACHING_MANGANATO_FETCH_SYMBOLIC_LINK_TTL_IN_SECONDS='0' \
ENMA_CACHING_MANGANATO_FETCH_SYMBOLIC_LINK_TTL_IN_SECONDS='0' \
pytest --cov=. --cov-report=xml ./tests
- name: Building and Deploying
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@ jobs:
ENMA_CACHING_MANGADEX_PAGINATE_TTL_IN_SECONDS='0' \
ENMA_CACHING_MANGADEX_SEARCH_TTL_IN_SECONDS='0' \
ENMA_CACHING_MANGADEX_GET_TTL_IN_SECONDS='0' \
ENMA_CACHING_MANGADEX_FETCH_SYMBOLIC_LINK_TTL_IN_SECONDS='0' \
ENMA_CACHING_MANGADEX_FETCH_SYMBOLIC_LINK_TTL_IN_SECONDS='0' \
ENMA_CACHING_NHENTAI_PAGINATE_TTL_IN_SECONDS='0' \
ENMA_CACHING_NHENTAI_SEARCH_TTL_IN_SECONDS='0' \
ENMA_CACHING_NHENTAI_GET_TTL_IN_SECONDS='0' \
ENMA_CACHING_NHENTAI_FETCH_SYMBOLIC_LINK_TTL_IN_SECONDS='0' \
ENMA_CACHING_NHENTAI_AUTHOR_TTL_IN_SECONDS='0' \
ENMA_CACHING_NHENTAI_FETCH_SYMBOLIC_LINK_TTL_IN_SECONDS='0' \
ENMA_CACHING_NHENTAI_AUTHOR_TTL_IN_SECONDS='0' \
ENMA_CACHING_MANGANATO_PAGINATE_TTL_IN_SECONDS='0' \
ENMA_CACHING_MANGANATO_SEARCH_TTL_IN_SECONDS='0' \
ENMA_CACHING_MANGANATO_GET_TTL_IN_SECONDS='0' \
ENMA_CACHING_MANGANATO_FETCH_SYMBOLIC_LINK_TTL_IN_SECONDS='0' \
ENMA_CACHING_MANGANATO_FETCH_SYMBOLIC_LINK_TTL_IN_SECONDS='0' \
pytest --cov=. --cov-report=xml ./tests
- name: Building and Deploying
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@ jobs:
ENMA_CACHING_MANGADEX_PAGINATE_TTL_IN_SECONDS='0' \
ENMA_CACHING_MANGADEX_SEARCH_TTL_IN_SECONDS='0' \
ENMA_CACHING_MANGADEX_GET_TTL_IN_SECONDS='0' \
ENMA_CACHING_MANGADEX_FETCH_SYMBOLIC_LINK_TTL_IN_SECONDS='0' \
ENMA_CACHING_MANGADEX_FETCH_SYMBOLIC_LINK_TTL_IN_SECONDS='0' \
ENMA_CACHING_NHENTAI_PAGINATE_TTL_IN_SECONDS='0' \
ENMA_CACHING_NHENTAI_SEARCH_TTL_IN_SECONDS='0' \
ENMA_CACHING_NHENTAI_GET_TTL_IN_SECONDS='0' \
ENMA_CACHING_NHENTAI_FETCH_SYMBOLIC_LINK_TTL_IN_SECONDS='0' \
ENMA_CACHING_NHENTAI_AUTHOR_TTL_IN_SECONDS='0' \
ENMA_CACHING_NHENTAI_FETCH_SYMBOLIC_LINK_TTL_IN_SECONDS='0' \
ENMA_CACHING_NHENTAI_AUTHOR_TTL_IN_SECONDS='0' \
ENMA_CACHING_MANGANATO_PAGINATE_TTL_IN_SECONDS='0' \
ENMA_CACHING_MANGANATO_SEARCH_TTL_IN_SECONDS='0' \
ENMA_CACHING_MANGANATO_GET_TTL_IN_SECONDS='0' \
ENMA_CACHING_MANGANATO_FETCH_SYMBOLIC_LINK_TTL_IN_SECONDS='0' \
ENMA_CACHING_MANGANATO_FETCH_SYMBOLIC_LINK_TTL_IN_SECONDS='0' \
pytest --cov=. --cov-report=xml ./tests
- name: Upload Report to Codecov
Expand Down
2 changes: 2 additions & 0 deletions enma/infra/core/utils/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ def wrapper(*args, **kwargs):
else:
_args = list([*list(kwargs.values()), *args[1:]])

print(_args)

if self._CACHE.get(str(_args)) is not None:
logger.debug(f'Retrieving cached object with key {str(_args)}')
return self._CACHE.get(str(_args))
Expand Down
4 changes: 2 additions & 2 deletions tests/test_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ def fibonacci(self, n):
# Assert that the function is only executed once and the cached result is returned
assert result1 == result2 == result3

assert cache._CACHE.get(str({5})) == result1
assert cache._CACHE.get(str([5])) == result1

# Call the fibonacci function with a different argument
result4 = fib.fibonacci(10)

# Assert that a new execution is performed and the result is cached
assert result4 == 55
assert cache._CACHE.get(str({10})) == result4
assert cache._CACHE.get(str([10])) == result4

def test_cache_expiration():
# Create an instance of the Cache class with a short expiration time
Expand Down

0 comments on commit f9ec4b5

Please sign in to comment.