Version: v0.6.0 - 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) {

    $key = 'posts:' ~ $userId;

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

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

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

    return $posts;
}