Skip to content

Commit

Permalink
Issue #2 more fine-tuning
Browse files Browse the repository at this point in the history
  • Loading branch information
soxofaan committed Sep 19, 2022
1 parent 181dd11 commit a5b80b0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/openeo_aggregator/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from openeo.capabilities import ComparableVersion
from openeo.rest import OpenEoApiError, OpenEoRestError, OpenEoClientException
from openeo.util import dict_no_none, TimingLogger, deep_get, rfc3339
from openeo_aggregator.caching import TtlCache, memoizer_from_config
from openeo_aggregator.caching import TtlCache, memoizer_from_config, Memoizer
from openeo_aggregator.config import AggregatorConfig, STREAM_CHUNK_SIZE_DEFAULT, CACHE_TTL_DEFAULT, \
CONNECTION_TIMEOUT_RESULT, CONNECTION_TIMEOUT_JOB_START
from openeo_aggregator.connection import MultiBackendConnection, BackendConnection, streaming_flask_response
Expand Down Expand Up @@ -793,7 +793,7 @@ def __init__(self, backends: MultiBackendConnection, config: AggregatorConfig):
self._configured_oidc_providers: List[OidcProvider] = config.configured_oidc_providers
self._auth_entitlement_check: Union[bool, dict] = config.auth_entitlement_check

self._memoizer = memoizer_from_config(config=config, namespace="general")
self._memoizer: Memoizer = memoizer_from_config(config=config, namespace="general")
self._backends.on_connections_change.add(self._memoizer.invalidate)

# Shorter HTTP cache TTL to adapt quicker to changed back-end configurations
Expand Down
8 changes: 7 additions & 1 deletion src/openeo_aggregator/caching.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,13 @@ def flush_all(self):

class Memoizer(metaclass=abc.ABCMeta):
"""
(Abstract) base class for function call caching (memoization).
(Abstract) base class for function call caching (memoization)
with this usage pattern (get from cache or calculate and cache that result):
value = memoizer.get_or_call(
key="foo",
callback=calculate_foo
)
Concrete classes should just implement `get_or_call` and `invalidate`.
"""
Expand Down
2 changes: 1 addition & 1 deletion src/openeo_aggregator/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def __init__(
self._configured_oidc_providers = configured_oidc_providers

# General (metadata/status) caching
self._memoizer = memoizer or NullMemoizer()
self._memoizer: Memoizer = memoizer or NullMemoizer()

# Caching of connection objects
self._connections_cache = _ConnectionsCache(expiry=0, connections=[])
Expand Down

0 comments on commit a5b80b0

Please sign in to comment.