THT is in early Beta. We welcome contributors & feedback.

Cache.get

Cache.get(key)

Description

Get the cached data for the given string key.

If the cached value does not exist, it will return an empty string ''.

Full example:

function getPostsForUser(userId) {

    let key = 'posts:' ~ userId;

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

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

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

    return posts;
}