如何缓存频繁服务的图像?

时间:2017-07-04 05:07:04

标签: caching grails

我使用的是旧版本的grails。 grails版本是2.2.0。我在当前的应用程序设置中看到的一个问题是日志充斥着来自索引页面的图像获取请求。如果我单击刷新,则重新请求所有图像。图像的日志记录如下所示

27.34.20.149 - - [03/Jul/2017:22:50:20 -0600] "GET /uploads/logos/thumbnails/f6dfNSxvksQkrB83_thumb.jpg HTTP/1.1" 404 1599
27.34.20.149 - - [03/Jul/2017:22:50:20 -0600] "GET /uploads/logos/thumbnails/I7w4dlwL1ejngl24_thumb.jpg HTTP/1.1" 404 1599
27.34.20.149 - - [03/Jul/2017:22:50:20 -0600] "GET /uploads/logos/thumbnails/eZhBkSt2BQK9fHES_thumb.jpg HTTP/1.1" 404 1599
27.34.20.149 - - [03/Jul/2017:22:50:20 -0600] "GET /uploads/logos/thumbnails/Wa7tHggCCmf95GH7_thumb.jpg HTTP/1.1" 404 1599
27.34.20.149 - - [03/Jul/2017:22:50:20 -0600] "GET /uploads/logos/thumbnails/3rCuZaRedGvhJGx9_thumb.jpg HTTP/1.1" 404 1599
27.34.20.149 - - [03/Jul/2017:22:50:20 -0600] "GET /uploads/logos/thumbnails/23i2HLxd1XbA0Bvd_thumb.jpg HTTP/1.1" 404 1599
27.34.20.149 - - [03/Jul/2017:22:50:20 -0600] "GET /uploads/logos/thumbnails/lbsBuqo1Imny2Ggl_thumb.jpg HTTP/1.1" 404 1599
27.34.20.149 - - [03/Jul/2017:22:50:20 -0600] "GET /uploads/logos/thumbnails/xtTZU9vrIHzct8sN_thumb.jpg HTTP/1.1" 404 1599
27.34.20.149 - - [03/Jul/2017:22:50:20 -0600] "GET /uploads/logos/thumbnails/rbUZx7D59tP67pfs_thumb.jpg HTTP/1.1" 404 1599
27.34.20.149 - - [03/Jul/2017:22:50:20 -0600] "GET /uploads/logos/thumbnails/7s47yiB3BmAnzMNX_thumb.jpg HTTP/1.1" 404 1599
27.34.20.149 - - [03/Jul/2017:22:50:20 -0600] "GET /uploads/logos/thumbnails/4TvirWFiuhdpWz7I_thumb.jpg HTTP/1.1" 404 1599
27.34.20.149 - - [03/Jul/2017:22:50:20 -0600] "GET /uploads/logos/thumbnails/oSBR4E5jH2m8iFiZ_thumb.jpg HTTP/1.1" 404 1599
27.34.20.149 - - [03/Jul/2017:22:50:21 -0600] "GET /uploads/logos/thumbnails/UGAVMxFQsotu2XNK_thumb.jpg HTTP/1.1" 404 1599
27.34.20.149 - - [03/Jul/2017:22:50:21 -0600] "GET 

这些是应用程序索引页面中的图像,这些图像不会经常更改。我想知道一个手动解决方案来缓存这些图像,以便在每次刷新页面时,不会从应用程序重新请求所有这些图像。我感谢任何帮助!谢谢!

1 个答案:

答案 0 :(得分:1)

高速缓存资源插件非常适合Grails 2(首先提及Mike W!)。

如果您计划在未来的某个时间点升级到2.4或3,那么您最好只看一下资产渠道:http://www.asset-pipeline.com/manual/#grails2http://plugins.grails.org/plugin/grails/asset-pipeline但这可能会更多现在为你工作。

但是,正如提醒一样,请注意您所包含的日志中的所有行都是404,并且每个行的URL都不同。在许多环境中,错误页面不会被缓存(它肯定取决于您的设置,但这是非常常见的,以避免误报)并且只要您要求不同资源每次(通过URL)缓存都没有帮助!