not found cache file
int MAX_MEMORY_CACHE_SIZE = 5*1024*1024;
private void initFresco(){
int maxHeapSize = (int) Runtime.getRuntime().maxMemory();
int use = ((maxHeapSize/4)/1024/1024);
android.util.Log.d(TAG,"use M:"+use);
String diskCachePath = Environment.getExternalStorageDirectory() + "/haha/";
File diskCacheDir = new File(diskCachePath);
ImagePipelineConfig.Builder builder = ImagePipelineConfig.newBuilder(this);
final MemoryCacheParams bitmapCacheParams = new MemoryCacheParams(
MAX_MEMORY_CACHE_SIZE, // Max total size of elements in the cache
Integer.MAX_VALUE, // Max entries in the cache
MAX_MEMORY_CACHE_SIZE, // Max total size of elements in eviction queue
Integer.MAX_VALUE, // Max length of eviction queue
Integer.MAX_VALUE); // Max cache entry size
builder.setBitmapMemoryCacheParamsSupplier(
new Supplier<MemoryCacheParams>() {
public MemoryCacheParams get() {
return bitmapCacheParams;
}
})
.setMainDiskCacheConfig(
DiskCacheConfig.newBuilder()
.setBaseDirectoryPath(diskCacheDir)
.setBaseDirectoryName("tqtest")
.setMaxCacheSize(40 * ByteConstants.MB)
.build());
ImagePipelineConfig config = builder.build();
Fresco.initialize(this,config);
at "Environment.getExternalStorageDirectory() + "/haha/tqtest" , not found cache file ??
Can you give the full stack trace where the error occurs please?
no error, below is log
05-20 09:31:10.640: D/tq(18839): use M:48 05-20 09:31:10.720: I/Adreno-EGL(18839): <qeglDrvAPI_eglInitialize:320>: EGL 1.4 QUALCOMM build: (CL3776187) 05-20 09:31:10.720: I/Adreno-EGL(18839): OpenGL ES Shader Compiler Version: 05-20 09:31:10.720: I/Adreno-EGL(18839): Build Date: 10/15/13 Tue 05-20 09:31:10.720: I/Adreno-EGL(18839): Local Branch: 05-20 09:31:10.720: I/Adreno-EGL(18839): Remote Branch: partner/upstream 05-20 09:31:10.720: I/Adreno-EGL(18839): Local Patches: 05-20 09:31:10.720: I/Adreno-EGL(18839): Reconstruct Branch: 05-20 09:31:10.750: D/OpenGLRenderer(18839): Enabling debug mode 0 05-20 09:31:10.770: D/dalvikvm(18839): Trying to load lib /data/app-lib/com.example.test-1/libmemchunk.so 0x41b77268 05-20 09:31:10.770: D/dalvikvm(18839): Added shared lib /data/app-lib/com.example.test-1/libmemchunk.so 0x41b77268 05-20 09:31:10.780: D/dalvikvm(18839): Trying to load lib /data/app-lib/com.example.test-1/libbitmaps.so 0x41b77268 05-20 09:31:10.780: D/dalvikvm(18839): Added shared lib /data/app-lib/com.example.test-1/libbitmaps.so 0x41b77268 05-20 09:31:10.960: I/ActivityManager(18839): Timeline: Activity_idle id: android.os.BinderProxy@41b74280 time:3104963
I'm not sure I quite understand your problem then? Which cache file is not found? What are you doing when it is not found?
I just look the cache file, but at disk cache dir (/storage/0/haha/) not found cache file ,
not support custom cache dir ?
No, we do support custom cache directories. Are you sure that no images are being loaded from disk cache? Can you verify that? What happens when you try to load an image from disk cache? If the cache isn't present I would expect an error of some sort.
I use file explore tool(for example ES ) to look the cache dir(/storage/0/haha/),but not found cache file. whether the cache file in cache dir? auto clear cache file ?
I understand that. But what happens when you actually try to load an image using Fresco?
nothing happens, just not found cache file, I thinks is "custom cache dir" not enable ?
Are you loading images from network? If the disk cache put fails then I would expect to see this error message: https://github.com/facebook/fresco/blob/master/imagepipeline/src/main/java/com/facebook/imagepipeline/cache/BufferedDiskCache.java#L236
No, if you configure your own custom cache dir then that will be enabled automatically.
not load image from network ,just local file (files://)
below is all code: package tq.test;
import java.io.File; import java.util.ArrayList;
import android.app.Activity; import android.content.ContentResolver; import android.database.Cursor; import android.net.Uri; import android.os.Bundle; import android.os.Environment; import android.provider.MediaStore; import android.util.DisplayMetrics; import android.view.View; import android.view.ViewGroup; import android.widget.AbsListView.LayoutParams; import android.widget.BaseAdapter; import android.widget.GridView;
import com.example.test.R; import com.facebook.cache.disk.DiskCacheConfig; import com.facebook.common.internal.Supplier; import com.facebook.common.util.ByteConstants; import com.facebook.drawee.backends.pipeline.Fresco; import com.facebook.drawee.view.SimpleDraweeView; import com.facebook.imagepipeline.cache.MemoryCacheParams; import com.facebook.imagepipeline.core.ImagePipelineConfig;
public class MainActivity extends Activity{
String TAG = "tq";
ArrayList<String> data;
public String[] STORE_IMAGES = {
MediaStore.Images.Media._ID,
MediaStore.Images.Media.DATA
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initFresco();
initData();
initView();
}
int MAX_MEMORY_CACHE_SIZE = 5*1024*1024;
private void initFresco(){
int maxHeapSize = (int) Runtime.getRuntime().maxMemory();
int use = ((maxHeapSize/4)/1024/1024);
android.util.Log.d(TAG,"use M:"+use);
String diskCachePath = Environment.getExternalStorageDirectory() + "/haha/";
File diskCacheDir = new File(diskCachePath);
ImagePipelineConfig.Builder builder = ImagePipelineConfig.newBuilder(this);
final MemoryCacheParams bitmapCacheParams = new MemoryCacheParams(
MAX_MEMORY_CACHE_SIZE, // Max total size of elements in the cache
Integer.MAX_VALUE, // Max entries in the cache
MAX_MEMORY_CACHE_SIZE, // Max total size of elements in eviction queue
Integer.MAX_VALUE, // Max length of eviction queue
Integer.MAX_VALUE); // Max cache entry size
builder
// .setBitmapMemoryCacheParamsSupplier(
// new Supplier
private void initView(){
DisplayMetrics displayMetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
double space = 6 * displayMetrics.density +0.5;
columnWidth = (int) ((displayMetrics.widthPixels - space * 5 ) / 4);
GridView gv = (GridView) findViewById(R.id.gv_show);
int s = (int)space;
gv.setHorizontalSpacing(6);
gv.setVerticalSpacing(6);
gv.setColumnWidth(columnWidth);
MAdapter adapter = new MAdapter();
gv.setAdapter(adapter);
}
private void initData(){
data = new ArrayList<String>();
ContentResolver contentResolver = getContentResolver();
Cursor cursor = contentResolver.query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
STORE_IMAGES, null, null, "date_modified desc");
if(null != cursor ){
for(cursor.moveToFirst();cursor.moveToNext();){
String path = cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media.DATA));
data.add(path);
}
}
cursor.close();
}
int columnWidth;
class MAdapter extends BaseAdapter{
@Override
public int getCount() {
// TODO Auto-generated method stub
return data.size();
}
@Override
public String getItem(int position) {
// TODO Auto-generated method stub
return data.get(position);
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
SimpleDraweeView v = new SimpleDraweeView(getApplicationContext());
LayoutParams params = new LayoutParams(columnWidth, columnWidth);
v.setLayoutParams(params);
v.setImageURI(Uri.parse("file://"+getItem(position)));
return v;
}
}
}
Ah. Local files are not stored in Fresco's disk cache.
Hello every one! I have a problem with fresco. I take a photo and load to preview activity to show it. I take a another photo again. I only load the last photo. Why fresco not update to disk cache? How way to fix it? sorry if you understand. My english 's not good.
Ah. Local files are not stored in Fresco's disk cache.
what if its not a local file means it would be url of image? how can we find it from cache file
This is my fresco initialization code below under my Application class // Configuring the disk cache DiskCacheConfig mainDiskCacheConfig = DiskCacheConfig.newBuilder(getApplicationContext()) .setBaseDirectoryName("ProductImage") .setBaseDirectoryPath(getApplicationContext().getCacheDir()) .build(); ImagePipelineConfig config = ImagePipelineConfig.newBuilder(getApplicationContext()) .setMainDiskCacheConfig(mainDiskCacheConfig) .build();
// Initialize Fresco Fresco.initialize(getApplicationContext(), config);
I download my image when I save it in the database by using below code inside for loop for(int i=0;i<10;i++{ getImageRequest( brandListURL.get(i).brandImage ); getImageRequest( brandListURL.get(i).brandImage1 ); getImageRequest( brandListURL.get(i).brandImage2 ); getImageRequest( brandListURL.get(i).brandImage3 ); getImageRequest( brandListURL.get(i).brandImage4 );
}
public static void getImageRequest( String brandUrl){ final File[] imagePath = new File[1]; if(brandUrl!=null) { if(brandUrl.contains("&") ){ brandUrl=brandUrl.replace("&","%20").replace(" ", "%20"); } else{ brandUrl =brandUrl.replace(" ", "%20"); } ImageRequest imageRequest = ImageRequestBuilder .newBuilderWithSource(Uri.parse(brandUrl)) .setRequestPriority(Priority.HIGH) .setAutoRotateEnabled(true) .setLocalThumbnailPreviewsEnabled(true) .setLowestPermittedRequestLevel(ImageRequest.RequestLevel.FULL_FETCH) .build(); //Download Fresco.getImagePipeline().prefetchToDiskCache(imageRequest, null);
return imageRequest;
}
}
I retrieve it from cache using this method
// imgHeader is Simple DraweeView Uri uri = Uri.parse(BRAND_IMAGE_URL + brandDAO.get(i).brandName.replace(" ", "%20").replace("&", "_") + ".jpg"); // imgHeader.setImageURI(uri); ImageRequest request = ImageRequestBuilder.newBuilderWithSource(uri) .setRequestPriority(Priority.HIGH) .setAutoRotateEnabled(true) .setLocalThumbnailPreviewsEnabled(true) .setLowestPermittedRequestLevel(ImageRequest.RequestLevel.FULL_FETCH) .build();
// getCacheFile methodis below in code
File imageFile = Utility.getCacheFile(request);
if (imageFile.exists()) {
String imagePath = imageFile.getAbsolutePath();
Uri uri1 = Uri.fromFile(imageFile);
imgHeader.setImageURI(uri1);
}else{
imgHeader.setImageURI(uri);
}
This method sometimes return file but sometimes not
public static File getCacheFile(final ImageRequest request) { FileCache mainFileCache = ImagePipelineFactory .getInstance() .getMainFileCache();
final CacheKey cacheKey = DefaultCacheKeyFactory
.getInstance()
.getEncodedCacheKey(request,null);
File cacheFile = request.getSourceFile();
if (mainFileCache.hasKey(cacheKey)) {
cacheFile = ((FileBinaryResource) mainFileCache.getResource(cacheKey)).getFile();
}
return cacheFile;
}
Hello every one! I have a problem with fresco. I take a photo and load to preview activity to show it. I take a another photo again. I only load the last photo. Why fresco not update to disk cache? How way to fix it? sorry if you understand. My english 's not good.
you need to evict the previous image from disk cache use this code // initialize imagePipeline
ImagePipeline imagePipeline = Fresco.getImagePipeline();
// evict from disk cache if(brandURL!=null) imagePipeline.evictFromDiskCache(Uri.parse(brandURL));