HTTP static resources caching forever stategy

痞子三分冷 提交于 2019-12-08 16:31:37

问题


In Effective Android HTTP Jesse Wilson mentioned the following:

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

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?

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?


回答1:


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

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

Cache-Control: max-stale=31536000


来源:https://stackoverflow.com/questions/23257725/http-static-resources-caching-forever-stategy

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