Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to cache requests #83

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft

Conversation

fgenoese
Copy link
Collaborator

This is a proposal to have the option to cache the response of requests using the library "requests_cache".

The way it is implemented is:

  • additional parameter named 'cache_expire_after' when creating a client (measured in seconds)
  • library will automatically store request in a file named entsoe-py_cache.sqlite
  • library will automatically remove expired responses; a check is done

code example:

from entsoe import EntsoeRawClient
client = EntsoeRawClient(api_key=<YOUR API KEY>, cache_expire_after=3600) ##seconds
start = pd.Timestamp('20171201', tz='Europe/Brussels')
end = pd.Timestamp('20180101', tz='Europe/Brussels')
country_code = 'BE'  # Belgium
client.query_load(country_code, start, end)

This is for discussion, let me know what you think.

@JrtPec
Copy link
Contributor

JrtPec commented Nov 19, 2020

What if we just use functools' lru_cache?

just put something like @functools.lru_cache(maxsize=128, typed=False) above the base request call? See https://docs.python.org/3/library/functools.html#functools.lru_cache

@pee-po
Copy link
Contributor

pee-po commented Feb 5, 2024

I know this is old but I'll weigh in. It's a cool idea but changing things globally would be a burden for users. The package already allows for dependency injection and it would be better for the users to configure persistently cached session (from the same package that @fgenoese proposed).

However what can be done is some sensible cache filter. Also - caching is a good idea for automated tests.

@fleimgruber
Copy link
Contributor

Another strategy is implementing caching in user code using e.g. https://pypi.org/project/diskcache. The library has a small API surface and can be used in slim functions wrapping the entsoe-py API. We use it for caching the pandas DataFrames as returned from EntsoePandasClient and the experience is good so far.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants