DiskCache encryption and decryption of Glide Images? - android

How to encrypt and decrypt disk cache images in android using Glide ?

Hi one idea would be create a cache decoder / encoder and use a library such https://github.com/facebook/conceal to do the hard encrypt / decrypt lift.
This image might help you navigate through the life cycle of glide:

Related

Is it safe to use Glide Caching instead of Internal Storage

I have a scenario where i have to keep few images in offline mode. Now i am confused here that should i rely on Glide's cache or I have to put those images in Internal Storage?
Hopefully Glide will work, but need to know if there exists any limitation if i go with Glide. Here word cache is causing confusion.
Here is the information about underlying memory usage by Glide.
Glide uses DiskLruCacheWrapper as the default DiskCache. DiskLruCacheWrapper is a fixed size disk cache with LRU eviction. The default disk cache size is 250 MB and is placed in a specific directory in the Application’s cache folder.
Further underlying complexities of Glide are here. Hope confusion about the max memory Glide uses is cleared here and if customization is needed, that can also be achieved by following the link mentioned.

Whether picasso supports image disk caching

Before I had worked on Volley and I have used the DiskLruCache [link] with Volley to cache images on disk.
Now I have been working with app that is using Picasso.
I would like to know whether Picasso supports disk caching.
If it supports how can I fix the cache size.
Which will be useful when loading images from remote with disk caching?
Picasso supports disk caching, and it's relying on the HTTP client for this.
If you're using it with OkHttp, the default size for the disk cache will be around 50 MB (2% of total space, max 50MB, min 5MB).
If this doesn't meet your needs, you can either implement your own disk cache or manually initialise the OkHttpDownloader with a larger disk cache size when you initialise your Picasso using the Picasso.Builder.
I would recommend the latter, it should look something like
new Picasso.Builder(context).downloader(new OkHttpDownloader(MAX_CACHE_SIZE)).build();

Encryption while disk caching

So what I to achieve is to apply encryption while caching images on disk.
I have decided to go with Universal Image Loader, I understand I will have to add an custom
disk caching implementation of my own but I don't know where to start with.
How can I achieve this, encryption while writing byte stream in file and decryption while getting the stream only from file.
Any kind of help would be deeply appreciated :)
Thanks for not replying :P
But I did eventually end up solving it. And here is what I did, maybe It will help anyone else.
All I had to was to create a custom disk cache and custom downloader.
In custom disk caching class, in the method where UIL write byte stream to file, I encrypted the byte stream.
and In custom downloader, I override the method where it take byte stream from file and decrypted it.

Encryption in disk caching Picasso android

I am planning on implementing, Picasso with OKHTTP for Disk caching of images. But I also plan on having encryption on images caches on disk. What should I do? I couldn't find a single helpful link, that can guide me in the right direction. Any kind of help would be greatly appreciated.
If somebody is looking for an answer, here is how I achieved it.
Firstly I switched to UIL since it provides more customization than Picasso.
Then I customized the built in diskCache mechanism.
ImageLoaderConfiguration.Builder builder = new ImageLoaderConfiguration.Builder(getApplicationContext());
builder.threadPriority(Thread.NORM_PRIORITY - 2);
builder.threadPoolSize(5);
builder.imageDownloader(new CustomImageDownaloder(this, new OkHttpClient()));
builder.diskCache(new CustomDiskCache(cacheDir));
Now in CustomDiskCache just override the methods where it read bytes from network and save them to disk, read bytes encrypt them and save them. Similarly, when you are about to read from cache file, decrypt bytes and convert them to bitmap.
Hope it helps.

Image Cache in android

I need to download image url and store it in cache as bitmap.My qus is is there any config that i have to do inorder to store the image bitmaps in cache..? Is there any need to create any cache file?
You should try this librairy : https://github.com/square/pollexor
Well, you just can put it in the app's cache (context.getCacheDir()). What I'd recommend is to use wasp: a cool Android library to handle Bitmaps safely (safe == avoid OutOfMemory exceptions which are pretty common), based on a LRU cache.
It also allows you to download images in the background and get a callback once your image is downloaded... or automatically set the image to an ImageView once it gets downloaded. It is open-source, and is available for Maven users too.
Disclaimer: I'm one of the developers working on wasp library.
Depending on how many images you want to cache, you can probably get away with an in-memory cache using a LruCache. I'd cache the downloaded byte array, not the Bitmap, because Bitmaps are Big Things and decoding byte array -> Bitmap is pretty fast.

Categories

Resources