• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Image Caching

 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Steffy's message in a previous thread made me think about whether an image caching framework would be useful.
What I mean by an image caching framework is:
  • There's a remote server serving image descriptor files (XML, property file, binary, something else)
  • The client has a component called "ImageCache", which can be configured to point at a specific URL, the remote server's "image cache root".
  • ImageCache.getImage(String id) checks whether the requested image is locally cached on the device and if not, fetches it from the server. The fetching would actually include fetching the image descriptor and the actual image file. The descriptor would have instructions on how often the client should refresh its copy and other useful information. The idea being that the application developer could define an optimal caching strategy for each particular application using the caching descriptors.


  • Do you see a need for this kind of utility or is it just "cool and unnecessary complexity"?
     
    Author
    Posts: 60
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Good idea. I've made a start in the ImageViewer example in the book, although it doesn't have your image descriptor idea. The book example uses a web service to retrieve the image and put it in a local cache, which uses an RMS database on the Palm and a binary file on the filesystem on the PocketPC. The web service has two methods: one to retrieve a list of descriptors (which is just a string in my example) for available images on the server, and another to retrieve an image object, which has attributes of the image itself, as well as the timestamp when it was last modified.
     
    Lasse Koskela
    author
    Posts: 11962
    5
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Interesting. Now I really have to get the book
    I wonder what would be an appropriate algorithm for managing the cache regarding memory consumption... In J2SE/J2EE applications using weak references within the cache implementation would probably be enough (cached objects would be gc'd before anything else) but how about a J2ME app?
     
    Daryl Wilding-McBride
    Author
    Posts: 60
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    My example uses the file system for the cache rather than memory, but you still need to know whether it's dirty or not. These approaches come to mind:
  • Retrieve it from the cache until it's a certain age, then ask the server whether there's a new copy available.
  • Whenever you access the server for any reason, ask it whether any cached images need to be refreshed.
  • Poll the server at regular intervals, asking whether any of the images should be refreshed.

  • For the last two, either the server would need to remember which images the client has already seen and when (which probably wouldn't scale very well), or the client would need to tell the server which images were in its cache and how old they were.
    [ July 24, 2003: Message edited by: Daryl Wilding-McBride ]
     
    Lasse Koskela
    author
    Posts: 11962
    5
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    I was kinda settled on the server giving a validity period along with each over-the-network fetch.
    Anyway, about the memory consumption... How could one control the amount of memory/storage used for caching? Here are my initial thoughts:
  • Persist a preferences file with a property "imagecache.maxsize"
  • Upon startup, read the maximum size used for caching and compare it to the files already in the cache --> initialize the "available memory left for caching" variables used to determine whether the ImageCache component needs to make some room for the new entries (if the newcomer has a higher "caching priority")


  • How did you actually use the filesystem? Proprietary API? RMS?
     
    Daryl Wilding-McBride
    Author
    Posts: 60
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    On the Palm I used RMS. On the PocketPC I used FileInputStream and FileOutputStream. I didn't store images in memory, and I imagine on Palm using MIDP you would run out of memory pretty quickly.
     
    Ranch Hand
    Posts: 867
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    I imagine on Palm using MIDP you would run out of memory pretty quickly
    Sorry to interrupt
    Is MIDP a file type?
    And the second question is that
    1:Loading the image from the pocketPC
    2:Sending the image to pocketPC
    Which way is the best?
    Do I need to consider the transfer rite and the image size?
    thanks
     
    Lasse Koskela
    author
    Posts: 11962
    5
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Is MIDP a file type?


    MIDP stands for Mobile Information Device Profile and is not a file type. It's a J2ME profile, a kind of a category for certain types of mobile devices.

    And the second question is that
    1:Loading the image from the pocketPC
    2:Sending the image to pocketPC
    Which way is the best? Do I need to consider the transfer rite and the image size?


    What do you mean by "loading" and "sending"?
     
    Francis Siu
    Ranch Hand
    Posts: 867
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    What do you mean by "loading" and "sending"?
    Loading means that when the pocketPC received a signal,then according to the signal that loading the required image from pocketPC.
    Sending means that the server send a image to the pocketPC.
    thanks
     
    Ranch Hand
    Posts: 121
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Yes. I agreed that this is a good idea to put images to cache but if using local cache - RMS, will it run out memory space if i need a lot of images?
    if i use client's component - imagecache that suggested by lasse, will the content in the cache loss for centain circumstances like no battery.
    steffy
    [ July 25, 2003: Message edited by: Steffy Sing ]
     
    sing
    Ranch Hand
    Posts: 121
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    On the Palm I used RMS. On the PocketPC I used FileInputStream and FileOutputStream. I didn't store images in memory, and I imagine on Palm using MIDP you would run out of memory pretty quickly.


    I thought the RMS is consider memory?
    if using FileInputStream and FileOutputStream, we will facing slow display if the connection is slow, am i wrong?
     
    sing
    Ranch Hand
    Posts: 121
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    1:Loading the image from the pocketPC
    2:Sending the image to pocketPC
    Which way is the best?


    I think these two are the same.
     
    sing
    Ranch Hand
    Posts: 121
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Very thank you to two of you, i have some ideas to doing the application.
     
    Francis Siu
    Ranch Hand
    Posts: 867
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    I think these two are the same
    It is different
    Case 1:
    Consideration of transfer rate that only the signal for requesting the image from pocketPC and
    the latence of device loading the image
    Case 2:
    Transfer rate that involving the signal containing the image(large size slower than small size if in the normal condition)
     
    Lasse Koskela
    author
    Posts: 11962
    5
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    I agreed that this is a good idea to put images to cache but if using local cache - RMS, will it run out memory space if i need a lot of images?


    Caches usually have some algorithm for deciding what to keep and what to dump when resources are limited. For example, using the LRU (least recently used) algorithm the ImageCache would keep the cached data under, say, 50kb by throwing out the least recently used cached object when something new is to be cached (and the 50kb limit would be exceeded).

    if i use client's component - imagecache that suggested by lasse, will the content in the cache loss for centain circumstances like no battery.


    That depends. It would be possible to persist the cache's contents every now and then to RMS (avoiding content loss upon battery failure). On the other hand, once you've recharged the battery and open the application, the caching period is probably over and the application needs to refetch the image anyway.
    By the way, let's call our ImageCache with another name from now on (as it could be used for any static resource). MobileCache?
     
    Lasse Koskela
    author
    Posts: 11962
    5
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    I thought the RMS is consider memory?


    RMS is persistent memory. You can think of RMS as an API for accessing the device's "hard disk".
     
    reply
      Bookmark Topic Watch Topic
    • New Topic