NextJs server Actions
Answered
Amur catfish posted this in #help-forum
Amur catfishOP
Hello guys! I'm currently working on a project regarding finance where I authenticate a user and I offer various options to create a budget, add tranzactions and so on.
Doing this requires me to have a function that get the data, validates it and creates a connection beforehand.
My question is, is there a way to "cache" or somehow save the database connection instead of calling it in my let's say createBudget function which looks something like this:
Doing this requires me to have a function that get the data, validates it and creates a connection beforehand.
My question is, is there a way to "cache" or somehow save the database connection instead of calling it in my let's say createBudget function which looks something like this:
Answered by B33fb0n3
if you are in a serverful env, you can use the
pooling
option of your DB. Then your server will handle and reuse the connections. Of course you can also just cache data to directly get results5 Replies
@Amur catfish Hello guys! I'm currently working on a project regarding finance where I authenticate a user and I offer various options to create a budget, add tranzactions and so on.
Doing this requires me to have a function that get the data, validates it and creates a connection beforehand.
My question is, is there a way to "cache" or somehow save the database connection instead of calling it in my let's say createBudget function which looks something like this:
if you are in a serverful env, you can use the
pooling
option of your DB. Then your server will handle and reuse the connections. Of course you can also just cache data to directly get resultsAnswer
@B33fb0n3 if you are in a serverful env, you can use the `pooling` option of your DB. Then your server will handle and reuse the connections. Of course you can also just cache data to directly get results
Amur catfishOP
Thanks a lot for your answer. I was looking into the matter and it seems Redis would be a good layer for caching. I was wondering, what's your point of view on this. Would you rather go for a cache layer like redis or integrate pooling?
@Amur catfish Thanks a lot for your answer. I was looking into the matter and it seems Redis would be a good layer for caching. I was wondering, what's your point of view on this. Would you rather go for a cache layer like redis or integrate pooling?
I think both are two different things. One (pooling) is for handling your database connection and two (caching) is to cache data to get results faster/more efficient. Redis is a good option š
Amur catfishOP
Amazing, thank you so much for your input! Gonna go try some magic š
That sounds great! Happy to help