Answer the question
In order to leave comments, you need to log in
Picasso how to cache pictures correctly?
Good day.
It is necessary to display pictures in the listview (about 186 kb each).
Pictures are loaded from the server, uploaded using picasso, cached using OkHttp
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = null;
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.albums_item, null);
final ViewHolder viewHolder = new ViewHolder();
viewHolder.image = (ImageView) view.findViewById(R.id.image);
viewHolder.progress = (ProgressBar) view.findViewById(R.id.progressBar);
view.setTag(viewHolder);
} else {
view = convertView;
}
final ViewHolder holder = (ViewHolder) view.getTag();
holder.progress.setVisibility(View.VISIBLE);
Picasso picasso;
OkHttpClient okHttpClient;
okHttpClient = new OkHttpClient();
picasso = new Picasso.Builder(mContext)
.downloader(new OkHttpDownloader(okHttpClient))
.build();
picasso.with(mContext)
.load(getItem(position).getMain_photo_url())
.into(holder.image, new Callback() {
@Override
public void onSuccess() {
holder.progress.setVisibility(View.GONE);
}
@Override
public void onError() {
}
});
return view;
}
Answer the question
In order to leave comments, you need to log in
Picasso caches the image at the http level. Check the headers that the server that hosts the image gives (the keywords "Cache-Control", "public, max-age, max-stale")
If the server gives with a short "life" time, then theoretically it is possible, by inheriting the standard picasso http client, to slip the desired header - but it's hard. In general, the author himself answered this on the stack - look
. Also, you need to check the size of the disk cache and the cache in the RAM for picasso. But that's probably not your problem.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question