How to release information stored in database after pausing activity for some time?

Viewed 23

I'm building my Messenger app. There's table called "Loaded" in MySQL server, which basically stores a pair of VARCHAR: Who_requested - Who_loaded. It means that the user named "Who_requested" has loaded user named "Who_loaded" into their main chat page. So when "the main user" scrolls down to see more users below their chat page, the server will know what to load next (I'm implementing pagination in RecyclerView). It looks something like this:
enter image description here

The thing when user stops the app, I'd like to wait for like 15 minutes before releasing all information related to "the main user" in loaded table and restart the app (like the effects that you might notice in Youtube after putting Youtube in the background for a while). How to implement this?

1 Answers

Some methods are

One

The obvious way is to have a task/service running that prunes the out of date entries. The disadvantage is that this could die and never run again. So you have to have some way of restarting it.

Two

If you don't want to do the above, then another method is to use a trigger.

  1. Have an AfterInsert Trigger on the table
  2. Delete out-of-date entries

The advantage is that you don't need another task that could fail. The disadvantage is that if there are no new entries, then the table does not get pruned.

Three

When you fetch the entries to display/action, only fetch the ones that are newer than 15 minutes. This doesn't prune them, but everything works fine. And you use a task or trigger to delete them.

Related