Android Picasso - 如何获取缓存命中和下载的统计信息

Mar*_*arc 4 android picasso

我目前正在使用Picasso 2.0.1(之前也尝试过1.0.2)并从网络上的图片中获取位图.

一切都很好,我看到加载图像的改进...至少看起来更快.

我的问题是,如何从PICASSO的活动中获取统计数据?我想知道图片是从缓存中获取还是下载了...

我正在尝试使用com.squareup.picasso.StatsSnapshot获取信息,但它似乎没有更新...或者我没有正确使用它.

Picasso pi = Picasso.with(getActivity().getApplicationContext());
Bitmap bitmap = pi.load(url.toString()).get();
Log.d(this.getClass().getSimpleName(),"Cache hits:" + pi.getSnapshot().cacheHits + " Cache misses:" + pi.getSnapshot().cacheMisses);
Run Code Online (Sandbox Code Playgroud)

在加载调用之前和/或之后添加日志始终返回相同的结果

高速缓存命中:0高速缓存未命中:0

我做错了什么或如何获得这些信息?

提前致谢!

wel*_*k91 5

要获得David Hewitt描述的彩色三角形,您实际上必须像这样使用setIndicatorsEnabled

Picasso.with(mContext).setIndicatorsEnabled(true);
Run Code Online (Sandbox Code Playgroud)

您可以使用setLoggingEnabled来获取Picasso日志中的统计信息

Picasso.with(mContext).setLoggingEnabled(true);
Run Code Online (Sandbox Code Playgroud)

您可以使用"Picasso"过滤器搜索日志,并查看Picasso获取图像的位置以及所需的时间.非常便利!