After doing a number of mashups that involved caching feeds, I decided to
make a building-block service for this capability. I checked this in as
system/feedCache and it should start appearing in the builds.
It's a pretty clever service if I do say so myself. If you want a feed, go
through the feedCache service like this:
var feed = reader.get(feedCache.feedReference(url));
The feedCache will fetch and cache the feed for 24 hours by default (with no
background prefetching). The returned url will be to a local copy of the
feed. Subsequent calls as above will return the feed url of the cache, and
if the cached copy is stale, it will refresh it in the process.
If one wants the raw XML directly (e.g., you're not using the FeedReader
object), you can get that too:
var rawFeedXML = feedCache.feedContent(url);
Again, this will use the local cache if there is one and it's less than the
default 24 hours old, otherwise it will populate the cache and mark it with
a 24 hour lifespan.
You can control the cache settings on a per feed basis:
feedCache.cacheSettings(url, 6*60*60*1000, false);
This changes the cache lifespan of the requested url to 6 hours from 24
(still with no prefetching). Prefetching (periodic background refreshes)
can also be specified:
feedCache.cacheSettings(url, 1*60*60*1000, true);
This refreshes the cache every hour (+/- the five minute refresh interval),
so you're likely to get good response time.
Anyway, play with it - I think it might be useful in simplifying some of our
other samples - I'm going to rewrite blogactivity to use it to help
fine-tune the perf there. Let me know what you think!
P.S. I'm getting faster at this - conception to checkin was about 4 hours
dev time ;-). Probably because I spent a lot more time designing the
interface, then wrote the whole service in one shot, spent about 10 min
fixing typos and only about 20 min testing and debugging to a working state.
Then another hour tweaking, adding documentation, safety annotations,
license etc.
Jonathan Marsh - <http://www.wso2.com> http://www.wso2.com -
<http://auburnmarshes.spaces.live.com> http://auburnmarshes.spaces.live.com
_______________________________________________
Mashup-dev mailing list
[email protected]
http://www.wso2.org/cgi-bin/mailman/listinfo/mashup-dev