Forum Discussion

guidamedia2's avatar
13 years ago

Caching data to limit requests to API

I am looking for the best caching method. What I am trying to achieve is to store response strings from my API on a daily basis, and some data even longer.

I have been reading about caching data on the Roku, but not really sure what the best solution is. It doesn't sound like it is designed for this.

I put together some simple script to cache the response strings from my api to the registry, and it saves tons of time retrieving it from there, rather than hitting the site again.

I also have been reading about AsyncGetToFile(), but that is dumped, according to what I read, after the channel session is over. (I assume the session is over as soon as the end-user goes to the home screen).

So, if you were to store data daily, weekly, monthly, would you do it, and if so... how?

7 Replies

  • Yeah, that is what I was thinking. MSGreg, I appreciate you getting back to me on this. I guess most channels are using GetToFile() and store the results per session.
  • In general, yes I would guess that developers are storing per session to the local file system. Whether you need a cache or not all depends on the exact use of the data (and whether you want it to refresh or not while the channel is running...imagine a channel running all night, for example).

    roImageCanvas manages a cache for URLs specified in the data. That is why it also has PurgedCachedImages() function (see here for tips on how to use PurgeCachedImages).

    Hope this helps!
  • I put this on the back burner for a while, but now I really want to get some data cached. I am using AsyncGetToFile(filename), where filename = "temp:/fred.txt".

    AsyncGetToFile() is returning false. What am I doing wrong?
  • The device name for the temp filesystem is "tmp". So your filename should be "tmp:/fred.txt".

    --Mark
  • Thanks this got me a true result, however I am not getting data from event = wait(timeout%, m.Http.GetPort()), except for the responsecode of 200.

    Are there any good examples on how to use this and get xml?
  • You don't read the file system with an roURLTransfer object. You would typically use readasciifile("tmp:/fred.txt")

    - Joel