Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
andro23
Channel Surfer

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 3
andro23
Channel Surfer

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
Cessilva
Channel Surfer

Re: Cachefs Unpredictable Behaviour

 

Hi, could you put your code please?  It would be very helpful
 
0 Kudos
andro23
Channel Surfer

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
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.