问题
In my website i have a database intensive page which i cache for 5 mins. But still the performance is hit when the cache expires and the page has to be rendered freshly. I was thinking why not compute the page from a background process(like workling) once in 5 mins and store it in the cache and let the user request be serve from the cache everytime. And as a result no user have to wait for this page to be rendered.
Is there a efficient way to do it? Any help very much appreciated.
Thanks,
回答1:
I would recommend simply making a call to your web-server for the page from your background-job or cron job. Then you let your entire Rails stack handle the call. You could create a cron job to do this every 4-5 minutes and pass a parameter to the page to have it force a cache refresh, for example:
complex/page?force=true
Your controller/action/model would then check for the presence of this parameter. If force was present the page would not use the cached version, but would re-create the cache instead.
来源:https://stackoverflow.com/questions/4909717/how-to-store-a-database-intensive-page-into-cache-from-a-background-process-in-r