How to store a database intensive page into cache from a background process in rails

独自空忆成欢 提交于 2019-12-12 20:01:57

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!