question

ffedericoni avatar image
ffedericoni asked ·

Devices are caching images on a APL document

I have built a skill that displays an image. I use a simple APL document:

                {
                    "type": "Container",
                    "height": "100%",
                    "width": "100%",
                    "items": [
                        {
                            "type": "Image",
                            "source": "https://www.arpae.it/sim/datiiningresso/Immagini/Radar/nowcast.png",
                            "scale": "best-fit",
                            "position": "absolute",
                            "width": "100%",
                            "height": "100%"
                        }
                    ]
                }

The skill works fine in the simulator and it always retrieves the most recent image (the image is updated every hour), but when I run the skill on my real devices (Echo Show 5 and Fire TV), it displays old images. It seems the devices are caching the image. How can I avoid that?

alexa skills kitalexa presentation language
10 |2000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Alexander Martin avatar image
Alexander Martin answered ·

you could simply add a random parameter to the url:

"source": "https://www.arpae.it/sim/datiiningresso/Immagini/Radar/nowcast.png?t=${Math.random() * Math.PI}" 
2 comments
10 |2000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Thanks, it worked.

1 Like 1 ·

@Alexander Martin
Is it converted at runtime(in the response sent from the code) or on the device?

0 Likes 0 ·
newuser-1dfc4ceb-67dd-4133-8fae-5eb94263fc84 avatar image
newuser-1dfc4ceb-67dd-4133-8fae-5eb94263fc84 answered ·

Hello,

Let me start by saying this is the first skill I have ever built - complete novice

I'm developing a basic skill that will open with an image of my security camera's that's pulled from my security camera server. I have stunnel installed to provide a secure connection and have signed certificates installed. All is working well in the simulator and on my Echo Show 8 (using the above work around for the image caching) however the Echo Show 5's don't seem to work with the above work around. Can someone help me? I'm I doing something wrong? Here is my complete APL:

The behaviour is very strange on the Echo Show 5. It will work if you call the skill again within about 5-10 minutes but if let sat for any length of time it caches the image. Device restart does not help and I cant find a way to delete the cache within the skill code. Any other suggestions of how i can fix this would be welcome!

I was maybe thinking that some how the echo show 5 is not processing the math in the ALP document. If i change the URL to anything it will refresh the image OK. The image also takes slightly longer to load when its cached which is the opposite of what you would think.

I have tired changing the version of both the APL and alexa-layouts to an older version and no joy as well.

{
    "type": "APL",
    "version": "1.5",
    "description": "This APL document places text on the screen and includes a button that sends the skill a message when selected. The button is a pre-defined responsive component from the alexa-layouts package.",
    "import": [
        {
            "name": "alexa-layouts",
            "version": "1.2.0"
        }
    ],
    "mainTemplate": {
        "parameters": [
            "payload"
        ],
        "items": [
            {
                "type": "Container",
                "width": "100%",
                "height": "100%",
                "items": [
                    {
                        "type": "AlexaBackground",
                        "backgroundImageSource": "https://xxxxxxxxxxxx/image/allcams?t=${Math.random()}",
                        "backgroundScale": "best-fill"
                    },
                    {
                        "type": "Text",
                        "id": "helloTextComponent",
                        "height": "75%",
                        "text": "",
                        "textAlign": "center",
                        "textAlignVertical": "center",
                        "paddingLeft": "@spacingSmall",
                        "paddingRight": "@spacingSmall",
                        "paddingTop": "@spacingXLarge",
                        "style": "textStyleBody"
                    },
                    {
                        "type": "AlexaButton",
                        "alignSelf": "center",
                        "id": "fadeHelloTextButton",
                        "buttonText": "CLICK FOR LIVE CAMERA STREAM",
                        "primaryAction": [
                            {
                                "type": "OpenURL",
                                "source": "http://xxxxxxxxx/mjpg/allcams",
                                "onFail": {
                                    "type": "SetValue",
                                    "componentId": "errorText",
                                    "property": "text",
                                    "value": "Unable to open security cameras (${event.source.value})"
                                }
                            }
                        ]
                    },
                    {
                        "type": "SendEvent",
                        "arguments": [
                            "user clicked the button"
                        ]
                    }
                ]
            }
        ]
    }
}




10 |2000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

rahulmittal79 avatar image
rahulmittal79 answered ·


Thanks for the quick reply

10 |2000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.