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: 
mosten
Visitor

Caching of images

Is there some way to control the caching of images? It seems that the box will fetch the image the first time it is displayed and hold it in cache. The only reliable way to clear is to reboot the device.
0 Kudos
6 REPLIES 6
RokuKevin
Visitor

Re: Caching of images

The box automatically maintains a system wide LRU image cache.... In general, there is no user or developer control over this cache.

However, in order to speed up navigation between different springboards using the left and right arrows, we did add a PrefetchPoster() method to the roSpringboard class. The LoadSpringboardContent() function can be used in the context of the showSpringboardScreenWithNav() function that was part of the "Make your Springboard Screens Navigate to Next Item in Feed" post.

You would use the PrefetchPoster() method like so:



'*************************************************************
'** LoadSpringboardContent()
'*************************************************************
Function LoadSpringboardContent(screen as object, items as object, index as integer)
item = items[index]
if item <> invalid and type(item) = "roAssociativeArray" and screen <> invalid and type(screen)= "roSpringboardScreen" then
screen.AllowUpdates(false)
screen.SetDescriptionStyle("video") 'audio, movie, video, generic
' generic+episode=4x3, generic+audio=audio
screen.ClearButtons()
screen.AddButton(1,"Play")
screen.AddRatingButton(2,80,20)
screen.AddButton(3,"Go Back")
screen.SetStaticRatingEnabled(false)
screen.AllowUpdates(true)
screen.SetContent(item)
screen.Show()

leftPrefetchIndex = 0
if index > 0 then
leftPrefetchIndex = index - 1
elseif items.Count() > 0
leftPrefetchIndex = (items.Count() - 1)
endif

rightPrefetchIndex = 0
if index < (items.Count() - 1) then
rightPrefetchIndex = index + 1
elseif (items.Count() - 1) = index
rightPrefetchIndex = 0
endif

item = items[leftPrefetchIndex]
if item <> invalid and item.SDPosterUrl <> invalid and item.HDPosterUrl <> invalid then
screen.PrefetchPoster(item.SDPosterUrl, item.HDPosterUrl)
endif

item = items[rightPrefetchIndex]
if item <> invalid and item.SDPosterUrl <> invalid and item.HDPosterUrl <> invalid then
screen.PrefetchPoster(item.SDPosterUrl, item.HDPosterUrl)
endif

endif

End Function



BTW, the roPosterScreen does prefetching of images internally in the object.
0 Kudos
mosten
Visitor

Re: Caching of images

Kevin,

I'm not sure how prefetch helps, unless I misunderstand. The issue for me is that the roku player has a cached version of the image once it has been pulled. If I change the image server side and keep the same name, the image is pulled from cache and not the new image. The new image will not show up until the Roku has been rebooted.

It's an issue for things like rotating banner ads and just generally a pain. Any mistakes made with images in production can not be fixed in a sane manner. This is even more true for images that are hard-coded in the channel and fetched from a remote location.
0 Kudos
RokuKevin
Visitor

Re: Caching of images

No. We do not have any other way to control the caching of images.

If you really want to make sure that your channel displays a new image, I suggest changing the URL for the image in your feed.

--Kevin
0 Kudos
trebonius
Visitor

Re: Caching of images

Depending on how the cache works, you could probably add a random or time-based query string variable at the end of the image URL to force a re-fetch. Example:

http://example.com/bannerad.jpg?nocache=656546132

There are a few situations in which that won't work, but it's worth a shot.
0 Kudos
zimbra
Visitor

Re: Caching of images

"trebonius" wrote:
Depending on how the cache works, you could probably add a random or time-based query string variable at the end of the image URL to force a re-fetch. Example:

http://example.com/bannerad.jpg?nocache=656546132

There are a few situations in which that won't work, but it's worth a shot.


I tried to setup a cgi to return images (http://foo/cgi/foo.pl?title=blah) so I could auto-extract them from my media files, and the SDK hated the targets with '?' in them, so I gave up on it. Not sure it you'll have the same problem or not with an actual image file.
0 Kudos
mosten
Visitor

Re: Caching of images

The SDK doesn't hate targets with "?" in them. It just has to be done in a special way.

I think you can just do:

m.UrlBase = "http://www.whatever.com/script.pl?id=12345"

or

sn = "12345"
m.Whatever = "/script.pl?id="
m.UrlBase = "http://www.whatever.com"
rhttp = NewHttp(m.UrlBase + m.Whatever + sn)
rhttp.AddParam("query", sn)
0 Kudos