ASP.NET is not designed to host background tasks/jobs, but it's possible to do it, although it won't be 100% reliable.
Create a worker class that contains a timer that fires every X interval and empties the app cache and saves the data to the database. In global.asax, create a handler for Application_Start
and call the worker class' init method from there.
Also expose a flush method on your worker class that you call from the Application_Stop
event handlar in global.asax, to make sure you flush any outstanding data before the application shuts down.