Version: v0.5.1 - Beta.  We welcome contributors & feedback.  THanks!


Cache.set(key, value, expireSecs)


Set a value for ther given key, to be expired in expireSecs seconds.

If expireSecs is set to 0, the key will never expire. It will need to be explicitly removed via Cache.delete.

Tip: Use the Date module to create an easy-to-read expiration value.

Full example:

function getPostsForUser(userId) {

    let key = 'posts:' ~ userId;

    if (Cache.has(key)) {
        return Cache.get(key);

    // e.g. get posts from database
    let query = sql'select * from posts where userId = {}';
    let posts = Db.selectRows(query);

    Cache.set(key, posts, Date.hours(8));

    return posts;