Rails 异步缓存过期
我的应用程序使用“传统”缓存清理器(ActionController::Caching::Sweeper 的子类)来使缓存(本质上是片段)过期。
现在,缓存过期会将应用程序锁定几秒钟,这会对客户感知到的性能产生负面影响。
如果能够异步地使缓存过期,那就太好了,例如使用delayed_job(该应用程序当前托管在heroku上)。
不幸的是,简单地将handle_asynchronously 添加到清理器内的缓存过期函数似乎不起作用。
是否可以使用delayed_job异步使缓存片段过期?如果是这样,最好的做法是什么?
My application use a "conventional" cache sweeper (subclass of ActionController::Caching::Sweeper) to expire the cache (essentially fragments).
Now, the cache expiration locks the application for several seconds, with negative impact on the performance as perceived by the customer.
It would be great to be able to expire the cache asynchronously, eg using delayed_job (the application is currently hosted on heroku).
Unfortunately, simply adding handle_asynchronously to the cache expiration function within the sweeper doesn't seem to work.
Is it possible to expire cache fragments asynchronously with delayed_job? If so, what are the best practices to do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要手动使缓存过期。由于您使用的是 memcached,因此您只需要生成缓存键所需的任何数据。
然后,您可以编写一个延迟作业来直接访问缓存并删除所需的键。
下面是 Resque 的清理器示例:
You will need to manually expire the cache. Because you're using memcached, you just need any data required to generate the cache keys.
You can then write a delayed job to access the cache directly and delete the required keys.
Here's an example sweeper for Resque: