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

Cache.has

Cache.has(key)

Description

Returns true if the key exists and has not yet expired.

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 = {}';
    query.fill(userId);
    let posts = Db.selectRows(query);

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

    return posts;
}