- Notifications
You must be signed in to change notification settings - Fork673
Does python-gitlab support http based caching?#3172
-
Hi there 👋🏽 . |
BetaWas this translation helpful?Give feedback.
All reactions
Replies: 1 comment 3 replies
-
Hi@notsatyarth, the library itself does not, but it's extremely easy to add usinghttps://pypi.org/project/requests-cache/. It's been asked often enough that we should at least document it or maybe add it as an optional feature. I'm unfortunately busy now, but will come back here to give you an example if you don't find a solution yourself 🙇 Please note, it's not always good to cache by default, as you might get outdated data when fresh data might matter. |
BetaWas this translation helpful?Give feedback.
All reactions
-
Thanks@nejch ! I agree with the point you raise, however I would expect gitlab's etag header to be requested for this? So that should also help in invalidating the cache for those requests. |
BetaWas this translation helpful?Give feedback.
All reactions
-
@notsatyarth true, at least requests-cache handles all of that already (https://requests-cache.readthedocs.io/en/stable/user_guide/headers.html). So maybe less of an issue but depends on how paranoid about data accuracy you need to be 😅 Let me know how you go with this. Just found an old example of mine, which was as simple as this (obviously no granular caching here): importosimportgitlabimportrequests_cacheCACHE_DIR=Path.cwd()/".cache"CACHE_SECONDS=60*60*24GITLAB_URL="https://gitlab.example.com"requests_cache.install_cache(CACHE_DIR,expire_after=CACHE_SECONDS)gl=gitlab.Gitlab(GITLAB_URL,private_token=os.getenv("GITLAB_TOKEN"),per_page=100,retry_transient_errors=True,) |
BetaWas this translation helpful?Give feedback.
All reactions
-
Thank you again, the docs for helped for this too. Looks like gitlab apis do not have much caching in place either :) |
BetaWas this translation helpful?Give feedback.