Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6528009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T09:29:41+00:00 2026-05-25T09:29:41+00:00

i need to cache images (only 5 or up to 100) from the web

  • 0

i need to cache images (only 5 or up to 100) from the web and displayed in a listview. if the user selects a row of the listview the cache can be cleared. i had a look on some examples. some use external storage. some use internal and external. some objects..

so what are the advantages/disadvantages of internal storage ( http://developer.android.com/guide/topics/data/data-storage.html#filesInternal via getCacheDir()) and object cache (something like WeakHashMap or HashMap < String, SoftReference < Drawable > )?

a problem with softreferences seems to be that they may get gc’ed too fast ( SoftReference gets garbage collected too early) . what about the android internal storage? the reference sais “These files will be ones that get deleted first when the device runs low on storage.”.

does it make any difference to use a object cache or the temporary internal storage? except for the object cache should be a bit faster

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T09:29:41+00:00Added an answer on May 25, 2026 at 9:29 am

    Here are the few differences between the two:

    • Object cache is faster than internal storage, but has lower capacity.
    • Object cache is transient in nature while internal storage has longer life span
    • Object cache takes the actual space in the heap. Internal storage doesn’t. This is an important point, as making your object cache too large could cause the OutOfMemoryException even with SoftReference

    Now given those differences, they are not totally mutually exclusive. A lot of we implemented is using multi layer caching especially related to the image loading. Here are the steps that we use:

    • If the image hasn’t been cached, fetch from the URL and cache it in first level cache which is the SoftReference/WeakHashMap or even hard cache with limited size using LinkedHashMap
    • We then implement removeEldestEntry() in LinkedHashMap. Upon hitting the hard cache capacity, we move things to secondary cache which is the internal storage. Using this method, you don’t have to refetch the image from the URL + it’s still be faster and it frees up your memory
    • We ran a cleanup on timely basis on the background for the internal storage using LRU algorithm. You shouldn’t rely on Android to clean this up for you.

    We have made the multi layers caching a common component and have used it many of our projects for our clients. This technique is pretty much following to what L1, L2 cache in Computer Architecture.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need a way for cache images and html files in PhoneGap from my
I need to invalidate cache in a web application when related data is updated
I'm planning to develop a web service, i need to use in memory cache,
I need to cache images locally and was thinking about saving them as SerializableDictionary
I have found this example Lazy load of images in ListView from Fedor which
I need to send an image (as a downloadable file) from an ASP web
I have an app that will need to cache some images. I have read
I need a cache that responds to memory pressure like the one build-into ASP.NET.
I need to organize cache in mySql database for address - coordinates. What is
I need to clear all APC cache entries when I deploy a new version

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.