HTTP静态资源缓存永远状态 [英] HTTP static resources caching forever stategy

查看:179
本文介绍了HTTP静态资源缓存永远状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有效的Android HTTP 中,Jesse Wilson提到了以下内容:

In Effective Android HTTP Jesse Wilson mentioned the following:


提供像图像这样的静态资源?
使用永久URL并让它永久缓存

Serving static resources like images? Use a permanent URL and let it cache forever

我正在使用 Picasso ,带有特定的 OkHttp 实例,用于获取和缓存图像。我想知道如何设置让它永远缓存策略?

I am using Picasso with a specific OkHttp instance for fetching and caching images. I am wondering how to setup the let it cache forever strategy?

我只能考虑覆盖HTTP缓存控制头max-stale( Cache-Control:max-stale = )具有最高可能值,是否有另一种(更好)方式?

I can only think about overriding the HTTP cache control header max-stale (Cache-Control: max-stale=)with the highest possible value, is there another (better) way?

推荐答案

最佳方法是将服务器配置为包含一个很长的最大年龄。例如,使用此标题指定365天:

Best way is to configure your server to include a long max-age. For example, specify 365 days with this header:

Cache-Control: max-age=31536000

如果要在客户端上启用无限制缓存,可以使用long max-stale:

If you want to enable unlimited caching on the client, you can use a long max-stale:

Cache-Control: max-stale=31536000

这篇关于HTTP静态资源缓存永远状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆