Wiki source for CachingRSS

Show raw source

You seem pretty handy with regular expressions; would you mind whipping one up for me?

Given a URL,, I'd like to extract domain and feed, and then gel them together, domainfeed.

This way I can make all RSS requests cache by default, which will alleviate some of the bandwidth concerns.

In the RSS action, I'll check to see if the user has specified a cache file, and if not, I'll set it to domainfeed.xml.

What do you think?

Update: Nevermind the plea. I'm going to use PHP's parse_url().
that's what i would have proposed ;)

if ridiculous filenames don't bother you, there even is no need for that juggeling with the url-chunks. you can do it in one line:

%%(php)<? $rss_cache_file = md5($vars["url"]); ?>%%

due to the nature of the md5-algorithm this will **not** produce distinct results, but chances to get in conflict with other cache-files are fairly low (to be accurate 1:2^36).

as a matter of principle defining the cache-file should **never** be up to the user. your approach seems to be much better (not only as a fallback-mechanism). imagine you want to use the feed-action somwhere at my wiki. you wouldn't have any survey of what cache-files are already in use (actually zero, 'cause i am caching into a database table ;) but that won't help you with the onyx-lib). although you most likely would use a name, which is somehow connected to the sitename or url, the risk of interferences will be in some cases much higher as with the md5-method above or with a modified url-string.

instead it is a good idea to define caching timeframes individually for each feed, since some feeds are updated on a daily basis and really don't need a refresh every 30 minutes, whereas a snapshot of others is obsolete within seconds.


Hmm... so if I'm understanding you correctly:

- Remove the ability for the user to specify the cache file. (done)
- Add a parameter that will allow some control over the cache time?
I like this idea. Maybe set the default to 15 minutes, but allow a parameter to bring this up or down. However, make it so the user can never go lower than a certain number, around 5 minutes.

Thanks for the MD5 suggestion. I had already added new code to use part of the parsed URL, but I like your suggestion better.

-- JsnX
you got it! that's exactly what my feed-action does. the precise values are a matter of taste, i regard a default of 30 minutes as suitable. the job is done with a check if the parameter drops below a defined threshold (what a missing parameter actually does, an incorrect string parameter is taken likewise as zero). in those cases the argument is set to the default value, otherwise you can proceed with the given argument. it really is that simple. ;)

> Thanks for the MD5 suggestion.

the only //real// benefit is that the directory listing gets a daunting scientific look ;) but if you need to pick out a specific file (perhaps for debugging purposes) your former code is the better one.

Valid XHTML :: Valid CSS: :: Powered by WikkaWiki