Skip to content

Commit eb96baf

Browse files
committed
feat: add lazy refresh type for postgres, sql server and mysql
1 parent ec68022 commit eb96baf

File tree

5 files changed

+28
-0
lines changed

5 files changed

+28
-0
lines changed

cloud-sql/mysql/servlet/src/main/java/com/example/cloudsql/ConnectorConnectionPoolFactory.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ public static DataSource createConnectionPool() {
7373
config.addDataSourceProperty("ipTypes", "PUBLIC,PRIVATE");
7474
// [START cloud_sql_mysql_servlet_connect_unix]
7575

76+
// setting the refresh strategy to LAZY
77+
// to refresh the tokens when they are needed, rather than on a regular interval
78+
// this is recommended for serverless environments to
79+
// avoid background refreshes from throttling CPU.
80+
config.addDataSourceProperty("cloudSqlRefreshStrategy", "lazy")
81+
7682
// ... Specify additional connection properties here.
7783
// [START_EXCLUDE]
7884
configureConnectionPool(config);

cloud-sql/mysql/servlet/src/main/java/com/example/cloudsql/ConnectorIamAuthnConnectionPoolFactory.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ public static DataSource createConnectionPool() {
6060
// The Java Connector will handle SSL so it is unneccesary to enable it at the driver level.
6161
config.addDataSourceProperty("sslmode", "disable");
6262

63+
// setting the refresh strategy to LAZY
64+
// to refresh the tokens when they are needed, rather than on a regular interval
65+
// this is recommended for serverless environments to
66+
// avoid background refreshes from throttling CPU.
67+
config.addDataSourceProperty("cloudSqlRefreshStrategy", "lazy")
68+
6369

6470
// ... Specify additional connection properties here.
6571
// [START_EXCLUDE]

cloud-sql/postgres/servlet/src/main/java/com/example/cloudsql/ConnectorConnectionPoolFactory.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ public static DataSource createConnectionPool() {
7272
config.addDataSourceProperty("ipTypes", "PUBLIC,PRIVATE");
7373
// [START cloud_sql_postgres_servlet_connect_unix]
7474

75+
// setting the refresh strategy to LAZY
76+
// to refresh the tokens when they are needed, rather than on a regular interval
77+
// this is recommended for serverless environments to
78+
// avoid background refreshes from throttling CPU.
79+
config.addDataSourceProperty("cloudSqlRefreshStrategy", "lazy")
7580

7681
// ... Specify additional connection properties here.
7782
// [START_EXCLUDE]

cloud-sql/postgres/servlet/src/main/java/com/example/cloudsql/ConnectorIamAuthnConnectionPoolFactory.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ public static DataSource createConnectionPool() {
6161
// The Java Connector will handle SSL so it is unneccesary to enable it at the driver level.
6262
config.addDataSourceProperty("sslmode", "disable");
6363

64+
// setting the refresh strategy to LAZY
65+
// to refresh the tokens when they are needed, rather than on a regular interval
66+
// this is recommended for serverless environments to
67+
// avoid background refreshes from throttling CPU.
68+
config.addDataSourceProperty("cloudSqlRefreshStrategy", "lazy")
6469

6570
// ... Specify additional connection properties here.
6671
// [START_EXCLUDE]

cloud-sql/sqlserver/servlet/src/main/java/com/example/cloudsql/ConnectorConnectionPoolFactory.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ public static DataSource createConnectionPool() {
6161
// at the driver level.
6262
config.addDataSourceProperty("encrypt", "false");
6363

64+
// setting the refresh strategy to LAZY
65+
// to refresh the tokens when they are needed, rather than on a regular interval
66+
// this is recommended for serverless environments to
67+
// avoid background refreshes from throttling CPU.
68+
config.addDataSourceProperty("cloudSqlRefreshStrategy", "lazy")
69+
6470
// ... Specify additional connection properties here.
6571
// [START_EXCLUDE]
6672
configureConnectionPool(config);

0 commit comments

Comments
 (0)