Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Highlighted
Level 8

Cachefs Unpredictable Behaviour

I am writing an app that downloads some images during its runtime putting them in the cache (cachefs:/MyAppImages).
A 32GB microSD is attached to my Roku Ultra 4640X having the latest OS version 8.0.1 build 4042-29.
After restarting the app, sometimes it is able to find cachef:/MyAppImages with the images downloaded inside; other times it doesn't find the directory and it keeps on downloading the images again and again. When I go check the memory card usage in Settings -> System -> About, I find it having the same usage that it had right after Roku formatted it (1.7/31.4 GB). I was expecting that it won't remove my cached files unless the memory card is full and the device needs more space on the memory card for other usages. Any idea why it is doing that?
0 Kudos
3 Replies
Highlighted
Level 8

Re: Cachefs Unpredictable Behaviour

I changed my approach and created files on root cachefs:/ and it worked as expected and documented this time.
0 Kudos
Highlighted
Level 7

Re: Cachefs Unpredictable Behaviour

 

Hi, could you put your code please?  It would be very helpful
 
0 Kudos
Highlighted
Level 8

Re: Cachefs Unpredictable Behaviour

Hi Cessilva, sure! I use this function to download files to cachefs :

function DownloadFile(url as StringfileName as Stringas object
    returnValue = {}

    urlObj = CreateObject("roUrlTransfer")
    urlObj.SetRequest("GET")
    urlObj.SetUrl(url.EncodeUri())
    urlObj.RetainBodyOnError(true)
    urlObj.SetCertificatesFile("common:/certs/ca-bundle.crt")
    urlObj.InitClientCertificates()
    urlObj.AddHeader("X-Roku-Reserved-Dev-Id""")
    urlObj.AddHeader("Content-Type""text/plain")
    urlObj.AddHeader("Accept""*/*")

    port = CreateObject("roMessagePort")
    urlObj.SetMessagePort(port)

    filePath = "cachefs:/" + fileName
    if(urlObj.AsyncGetToFile(filePath))
        while(true)
            msg = wait(0port)
            if(type(msg) = "roUrlEvent")
                code = msg.GetResponseCode()
                if(code = 200)
                    returnValue.success = true
                    returnValue.filePath = filePath
                else
                    returnValue.success = false
                    returnValue.code = code
                    returnValue.errorMessage = "Failed to download file: '" + fileName + "'. Code: " + code.toStr() + ". Reason: " + msg.GetFailureReason()
                    urlObj.AsyncCancel()
                end if
            else
                returnValue.success = false
                returnValue.errorMessage = "Invalid event"
                urlObj.AsyncCancel()
            end if
            exit while
        end while
    else
        returnValue.success = false
        returnValue.errorMessage = "Download request could not be issued."
        urlObj.AsyncCancel()
    end if
    return returnValue
end function
0 Kudos