

【android】picasso加载本地图片如何清理缓存cache? | iTimeTraveler
source link: https://itimetraveler.github.io/2016/03/08/%E3%80%90Android%E3%80%91Picasso%E5%8A%A0%E8%BD%BD%E6%9C%AC%E5%9C%B0%E5%9B%BE%E7%89%87%E5%A6%82%E4%BD%95%E6%B8%85%E7%90%86%E7%BC%93%E5%AD%98cache%EF%BC%9F/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

【Android】Picasso加载本地图片如何清理缓存cache?
使用Picasso加载SD卡图片的时候,Picasso也会对该图片进行缓存。所以如果该图片即使已经变了,Picasso在加载时会仍然使用缓存,而不更新图片。
1、Picasso缓存策略
我们都知道图片缓存使用的是Map键值对存储的,这里的Key就是加载的图片的Url,所以如果我们使用相同的ImageUrl去加载图片的话,如果使用了缓存,Picasso会直接读取缓存的内容,而不是从SD卡、或者网络Http中重新加载。
2、Picasso如何跳过缓存
试了很多网上推荐的方法均不见起效,最后使用了下面这种策略,也就是加载图片时直接跳过缓存
Picasso.with(getContext()).load(imageUrl).memoryPolicy(MemoryPolicy.NO_CACHE).into(image);
注意其中的.memoryPolicy(MemoryPolicy.NO_CACHE)即是关键代码,其中
- MemoryPolicy.NO_CACHE:是指图片加载时放弃在内存缓存中查找。
- MemoryPolicy.NO_STORE:是指图片加载完不缓存在内存中。
ps:此处的方法并不是真正的清理缓存,而是跳过缓存直接从源头获取。
网上有几种错误的方法如下,经验证均不起效:
1、Picasso.with(getActivity()).invalidate(file);
2、Picasso.with(getActivity()).load(url).skipMemoryCache().into(image);
最后还是在StackOverFlow的Clear Cache memory of Picasso查到了如上的解决办法。
Recommend
-
78
Android 框架学习1:EventBus 3.0 的特点与如何使用 Android 框架学习2:源码分析 EventBus 3.0 如何实现事件总线 Android 框架学习3:我从 EventBus 中学到的精华通过本篇文章你将学到如下内容:假如我们来写一个框架走近 Picasso认识核心 API请求信息相关的类加...
-
13
Android开发之ListView异步加载图片_dmk877的专栏-CSDN博客ListView这个控件对于大家肯定不会陌生,即使你是初学者相信也会用ListView。因为ListView这个控件实在是太常用,可以说基本上每一个项目开发都会用到它,今天这篇博客主要讲解,ListView异步加载图片...
-
25
Android图片加载框架最全解析(八),带你全面了解Glide 4的用法 ...
-
8
Android图片加载框架最全解析(七),实现带进度的Glide图片加载功能 ...
-
12
最近开发的组件时常出现了运行时加载so库失败问题,每天都会有java.lang.UnsatisfiedLinkError的错误爆出来,而且线上总是偶然复现,很疑惑。所以本文将从AOSP源码简单跟踪Android中的动态链接库so的加载原理,试图找出一丝线索。 首先我们...
-
6
前言使用d3的力学图(力导向图)与生活中常见的人物关系图结合,已经有了很好的例子: 【 D3.js 进阶系列 — 2.0 】 力学图 + 人物关系图,博...
-
10
D3.js加载本地json文件的问题 打开本地html文件时,报错如下 XMLHttpRequest cannot load file:/cities.csv. Cross origin requests are only supported for protocol schemes: http, data, chro...
-
12
搬运原链接:http://stormzhang.github.io/android/2014/07/24/android-save-image-to-gallery 正文
-
5
Picasso A powerful image downloading and caching library for Android For more information please see the website Download Download the latest AAR from
-
7
How to Use Picasso Image Loader Library in AndroidHow to Use Picasso Image Loader Library in Android50 Views11/07/2022<p>In this vid...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK