locked
files from appdata are cached when app is running? RRS feed

  • Question

  • hi,

    i am writing an app demo, in the default.js, i add an img element with src="ms-appdata:///local/tmp.jpg",

    when the app running, my winrt componet will replace the tmp.jpg with other jpg files but keep the name unchanged.

    the logic of my code is like below:

    use click a button -> winrt function:replace the tmp.jpg -> javascript will remove the img element if exists, then create the same img elment with src="ms-appdata:///local/tmp.jpg"

    result is the UI doesn't change at all. always showing the original jpg.

    Sunday, May 6, 2012 8:54 AM

Answers

  • Hey Alan,

    Thanks for the suggestion.  I will file a bug on this.  In the mean time you could load the image from stream to get around the problem:

     theFile.openReadAsync().then(function (stream) {
                    var blob = MSApp.createBlobFromRandomAccessStream(stream.contentType, stream);
                    id("streamImg").src = URL.createObjectURL(blob, false);
                });
    -Jeff

    Jeff Sanders (MSFT)

    Monday, May 14, 2012 2:44 PM
    Moderator

All replies

  • Hi Ade,

    I do not have an easy repro here.  What happens if you set the img to a different source and then back to src="ms-appdata:///local/tmp.jpg"?  Does it update then?

    I am curious if the file gets cached or if the img element is smart enough to see that the src attribute did not change and that is why it is not updating.

    -Jeff


    Jeff Sanders (MSFT)

    Monday, May 7, 2012 3:24 PM
    Moderator
  • Hi Jeff,

    i have tried your advice,

    image.src = "ms-appdata:///local/switch.jpg";

    image.src = "ms-appdata:///local/tmp.jpg";

    still get the same result.

    it seems that :

    if the app can find the file content of the corresponding src in its cache, it won't reload the file from the disk.


    • Edited by adewang82 Tuesday, May 8, 2012 3:19 AM
    Tuesday, May 8, 2012 3:15 AM
  • Hi Ade,

    Same result... does that mean that if switch and tmp are differnet image files and you update the src attribute from one to the other, the UI does not update the display?

    -Jeff


    Jeff Sanders (MSFT)

    Thursday, May 10, 2012 3:13 PM
    Moderator
  • Hi Jeff,

    the ui does update the display.

    but as you can see, every call to the function will set the src to "ms-appdata:///local/tmp.jpg" finally,

    so this is not a solution to my question...   the ui still displays the original tmp.jpg.

    Friday, May 11, 2012 2:25 AM
  • They have to address this issue. There are a lot of scenarios that we CAN'T change the name of the file because of endless reasons.

    They should have something like a variable for the ms-appdata: that indicates it has to be loaded again.

    Saturday, May 12, 2012 5:56 PM
  • Hey Alan,

    Thanks for the suggestion.  I will file a bug on this.  In the mean time you could load the image from stream to get around the problem:

     theFile.openReadAsync().then(function (stream) {
                    var blob = MSApp.createBlobFromRandomAccessStream(stream.contentType, stream);
                    id("streamImg").src = URL.createObjectURL(blob, false);
                });
    -Jeff

    Jeff Sanders (MSFT)

    Monday, May 14, 2012 2:44 PM
    Moderator