caching strategy (philosophy)

Roku's free SDK allows developers to build channels and applications and publish them to the Roku Channel Store. Register for the Developer Program at http://www.roku.com/developer

Moderators: RokuDouglas, RokuKen, RokuRyan, RokuJamesL, RokuChris, RokuJoel

caching strategy (philosophy)

Postby jbrave » Sun Oct 10, 2010 1:35 am

not really asking a question here, just a comment if anyone wants to discuss

seems like many apps do lots of unnecessary reloading of content from the net. Well, when you first start on an app and you've never done this type of xml based data retrieval programming before, thinking this out is probably not as high a priority as learning and writing the app. I'm contemplating how to bolt a caching system onto the top of my app so that stuff only gets reloaded from the net when requested the first time, or the app is first loaded. If you can imagine what the cumulative cost of hundreds or thousands of clients with a poor caching system is for a company like YouTube for instance, or Netflix you can imagine that at some point unnecessary reloading is costing a hugh amount of money, which someone is paying for somewhere...

I'm not talking about predictive caching, but just storing information locally and only reloading when necessary.

Some ideas off the top of my head:

Use a separate posterlist variable for each category on your poster screen. Storing each posterlist in an roArray means you can use msg.Getindex() of posterscreen to select the to select the already loaded Posterlist:

Code: Select all

posterscreen=createObject("roPosterScreen")
listone=loadsearchitems() 'preload the title, description, URL's of searchItems
listtwo=loadfavoriteitems() 'same thing for favorite items
posterlist=[listone,listwo]
posterscreen.SetContentList(Posterlist[0])
port=CreateObject("roMessagePort")
posterscreen.SetPort(port)
posterscreen.show
while true
msg=wait(0,port)
if msg.isListFocused()
posterscreen.SetContentList(posterlist[msg.getIndex()]
end if
end while



There may be errors in the above, since I just wrote it off the top of my head, but maybe you get the idea of what I'm thinking of.

Some mechanism for determining when a user has requested to load the data for the first time and when they are trying to look at the same data again has to be worked out. That's what I'm thinking about now for my own app.

Now of course, That only covers caching xml and posteritems, not the artwork and data files that come over. Well, assuming the artwork files aren't that big, one could probably save that to local memory or USB if they have it, and reload it from there, of course, there would need to be some way to wipe it out, probably want to do that when the app is loaded or better, when the accumulated pile of files is greater than a certain amount, or older than a certain date. Something like

Code: Select all

if imageAge <> tooOld then
ImageURl(index)="pkg:/images/temp/image"+index+".png"
else
imageURL(index)="http://servername.com/temp/image"+".png"
end if



to try to throw together a quickee example from the top of my head....

So any philosophical comments?

- Joel
Screenshades: The first Screensaver for Roku2!
Musiclouds: The best free internet music, on your Roku!
Ouroborialis: Psychedelic Screensaver for Roku!
jbrave
 
Posts: 716
Joined: Mon Mar 22, 2010 3:00 pm
Location: Ben Lomond, CA

Re: caching strategy (philosophy)

Postby TheEndless » Sun Oct 10, 2010 9:27 am

jbrave wrote:That only covers caching xml and posteritems, not the artwork and data files that come over.

The Roku handles caching of images automatically, as long as the URL doesn't change. For caching data files, you can use the GetToFile method of the roUrlTransfer component to save them to tmp: on the first get, then load from there on subsequent requests.

One thing to consider when caching content is that the Roku does have limited memory available to it. The more you cache, the quicker you'll reach that limit, so you'll want to be wary of just how much data you're keeping resident in memory.
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), MainSqueeze (MAINSQUEEZE), iTunes Podcasts (ITPC), Twitch.tv (TWITCHTV), My Channels (MYCHANNELS)
User avatar
TheEndless
** Valued Community Member **
 
Posts: 8061
Joined: Mon Oct 04, 2004 10:15 am
Location: US

Re: caching strategy (philosophy)

Postby karmacode » Mon Oct 10, 2011 7:06 pm

One thing to consider when caching content is that the Roku does have limited memory available to it. The more you cache, the quicker you'll reach that limit, so you'll want to be wary of just how much data you're keeping resident in memory.


Any idea what that memory limit is?
http://www.connectedtvforum.com
karmacode
 
Posts: 12
Joined: Wed Jul 20, 2011 8:38 am


Return to Roku Developer Program

Who is online

Users browsing this forum: EnTerr and 4 guests