locked
Caching data on Client Side RRS feed

  • Question

  • I am using SL2B2 RC0 ... I am using WCF Service to retrive data through server... I want co cache data on client side that I have retrive through server for increased performance as sometimes its repeatition of data for me. Now as far as I know I can do following kind of caching

    1. using IsolatedStorage -- here problem is that I need to ask user if he wants to increase Quota Size and if he denies then I am limited to 1 MB default (taking in consideration that user has not made it to zero Smile )

    2. using Cookies -- here problem is that I can create cookie file of max size 4KB

    3. I can use in memory caching -- means keep retrived data with me on client side untill and unless my application session is running. But this will increase memory size and I need higher RAM on client side

     

    So is there anything else that I have with silverlight which will help me to cache WCF retrived data onto client??? and would appreciate if someone provides some example....

     

    Thanks in advance! Smile

    Tuesday, October 21, 2008 9:14 AM

Answers

  • You can always cache in memory by using lists/hashtables/dictionaries whatever data structure you like.  So that should achieve your goal no problem.  Yes this is RAM so the memory is volatile..however if the memory goes kaput, there are other problems with the system.  I don't know what you are targeting, but any computer purchased in the last 5-6 years is going to have at least 256 meg of RAM.  New machines have 2 gig+.

    You do have 1mb by default in Isolated Storage.  If you are dealing with 5kb images then you do have plenty to work with for the 1mb.

    If you really want to you can also leverage the Silverlight -> HTML Bridge and use Javascript caching using arrays for example.  I don't know why you would want to do this, but you can since both Silvelight/JavaScript will both use the browser's main memory.

    Other than these solutions there really isn't some other magic cache you can use.  It is pretty simple: cache in memory (Silverlight or JavaScript), use cookies like you mention (I don't think that is even an option for you), cache using Isolated Storage (1mb by default).

    Hope this helps.

    Wednesday, October 22, 2008 1:25 AM

All replies

  • you got all three possibilitys

     

    Tuesday, October 21, 2008 10:58 AM
  • Use Isolated Storage!  Cookies are not an option, because they are only 4kb like you mention.  Isolated Storage defaults to 1mb and you can increase this to 100mb if you want and the client agrees.  This is what you should be doing:

    - Silverlight needs some kind of data

    - Client checks if the data is in an in-memory data structure (if so it gets it from there)

    - If the data is not in memory, client checks the version of the data it has in Isolated Storage (for example it is data from 10/21/2008 or if you have a version on it version 1.1)

    - Call a WCF Service to find out the latest version of your data (whatever that is a date or a version)

    - If the version in Isolated Storage is the same as the one on the service then client loads data into memory from Isolated Storage

    - If the version in Isolated Storage is older, clear out the particular data inside Isolated Storage and then get the data from the WCF service

    - After retrieving the data from WCF, store the data inside Isolated Storage and then load it from there

     This pattern will allow you to keep your data current, while only requiring calls when the data has not been refreshed.  This works great for scenarios where the data is "slowly changing" (for example, once a week or once a month).  If it is daily or every hour, you might want to reconsider caching using Isolated Storage.  Furthermore, also note in the patter that we are using a combination of loading the data into memory with Isolated Storage..memory data structures are 100x faster than going to the HD.

    Here is an example from a post I did not too long ago on how to achieve this in Silverlight 2 RTM:

    http://silverlighthack.com/post/2008/09/29/Silverlight-2-(RC0-RTM)-Dynamic-Assembly-Loading.aspx

     

    Tuesday, October 21, 2008 11:53 AM
  • thanks Bart for your imp feedback... but the real problem is that I dont want anykind of authentication from client about quota increase or decrease for IsolatedStorage client should be unaware that there is something being cached in thier browser (I know this is un-ethical as this is virus kind of practice, but has to do) ... another thing is that using in-Memory as you said that it is always faster and that is fine ... but my concern goes if there is less volatile memory on client system .. so at point my application performance degrades ...

    If we take case of browser then any file that is retrived by browser is cached in clients Temporary files .. so if suppose I am sending some what 500 images of 5 kb each.. than all of them are cached there and I can very easily achieve it using JavaScript .. so if its possible through JavaScript then there should be some of more possibilities through Silverlight as well... need to find something like that

    Wednesday, October 22, 2008 12:39 AM
  • You can always cache in memory by using lists/hashtables/dictionaries whatever data structure you like.  So that should achieve your goal no problem.  Yes this is RAM so the memory is volatile..however if the memory goes kaput, there are other problems with the system.  I don't know what you are targeting, but any computer purchased in the last 5-6 years is going to have at least 256 meg of RAM.  New machines have 2 gig+.

    You do have 1mb by default in Isolated Storage.  If you are dealing with 5kb images then you do have plenty to work with for the 1mb.

    If you really want to you can also leverage the Silverlight -> HTML Bridge and use Javascript caching using arrays for example.  I don't know why you would want to do this, but you can since both Silvelight/JavaScript will both use the browser's main memory.

    Other than these solutions there really isn't some other magic cache you can use.  It is pretty simple: cache in memory (Silverlight or JavaScript), use cookies like you mention (I don't think that is even an option for you), cache using Isolated Storage (1mb by default).

    Hope this helps.

    Wednesday, October 22, 2008 1:25 AM
  • Hi Bart .. thanks for your response... let me check it out what works ....

    Wednesday, October 22, 2008 2:25 AM