Answer the question
In order to leave comments, you need to log in
How to auto-delete information from a database in a Java web application?
The question is rather architectural: I have a server written in Java + Spring mvc that receives data and writes it to the database, there is nothing new here. It is necessary to make sure that this data is stored for 3 days, and then deleted from the database. The question is: what is the best way to do this?
Now, I have only 3 options:
1. Add a thread to the server code, which will periodically wake up and clean the database.
2. Make a request from the site to clear the database. Using a regular JS script
3. Clean up the database every time a new data is received (every 10 seconds). It seems to me that this will load the server too much
. I can’t make a choice from them, for some reason they seem to me bad manners, perhaps there is a more competent way
Answer the question
In order to leave comments, you need to log in
There are many ways to delete after 3 days. It seems to me that a good option is to make a field according to the recording time. Further, at night, according to the schedule, a certain process is launched that looks at the time between the field and the current time. As an option, make another parameter for setting that the process can delete those records that are 3 days old, and next time you will change and make 5 days. That is, this process must have an input parameter, a la the number of days.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question