GoogleCloudPlatform / alloydb-python-connector

A Python library for connecting securely to your AlloyDB instances.
Apache License 2.0
25 stars 6 forks source link

feat: add support for lazy refresh strategy #337

Closed jackwotherspoon closed 2 weeks ago

jackwotherspoon commented 2 weeks ago

Add refresh_strategy argument to Connector() that allows setting the strategy to "lazy" to use a lazy refresh strategy.

When creating a Connector via Connector(refresh_strategy="lazy"), the connection info and ephemeral certificate will be refreshed only when the cache certificate has expired. No background tasks run periodically with this option, making it ideal for use in serverless environments such as Cloud Run, Cloud Functions, etc, where the CPU may be throttled.

Usage example:

from google.cloud.alloydb.connector import Connector

with Connector(refresh_strategy="lazy") as connector:
    # ... use connector in lazy refresh mode

Port of https://github.com/GoogleCloudPlatform/cloud-sql-python-connector/pull/1093

Closes #298