Aluminium

RSS Cache Example

This example shows off the fancy new feature that appeared in version 0.3, the XQuery :-).

As in previous examples, let's start with the database (we're using PostgreSQL this time):

CREATE TABLE rss
(
    id          serial,
    created     timestamp with time zone,
    title       varchar(255),
    link        varchar(255),
    summary     text,

    PRIMARY KEY (id),
    UNIQUE (link)
);

CREATE RULE same_link AS ON INSERT TO rss
  WHERE EXISTS (SELECT 1 FROM rss WHERE link=NEW.link)
  DO INSTEAD NOTHING;

The rss table will be used to store the feed items. We've also created a rule named same_link, to prevent insertions of already inserted items.

Next, the application code (no separate templates this time):

example_rsscache.png

The application is divided into two parts: one that retrieves the feed items and stores them into database, and another one that generates a new feed from the items in the database.

The first part starts with a script (pink operation, with comment "1"), which checks if the latest item in the database is older than one hour, and if it is, retrieves new items.

The second part starts with a HTTP response (another pink operation, with comment "2"), which outputs the new feed, that is generated from the items in the database.