Version: v0.7.0 - Beta.  We welcome contributors & feedback.

Cache.has

Cache.has($key) -> boolean

Description

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

Full example:

fn getPostsForUser($userId) {

    $key = 'posts:' ~ $userId

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

    // The time-consuming operation to be cached
    $posts = getPostsFromDb($userId)

    Cache.set($key, $posts, '8 hours')

    return $posts
}

See Also