{"body":"sub character-lookup(Int :$id) {\n    # check the cache first\n    my Bool $cached = True;\n    my $character = $redis.get($id);\n    # check the database if we didn't find it in the cache\n    if !$character {\n        $cached = False;\n        $character = Character.^load($id).to-json;\n        # cache the result we got from the database for 30 minutes\n        if $character { $redis.setex($id, 1800, $character); }\n    }\n    given $cached {\n        my $color; my $state;\n        when ?* { $color = 'red'; $state = '[HIT]' }\n        when !* { $color = 'blue'; $state = '[MISS]' }\n        note \"[{ DateTime.now }]\" ~ color($color),\" $state \" ~ color('reset'), \"Performing lookup on $id\";\n    }\n    # return the lookup result\n    return $character;\n}","name":"","extension":"txt","url":"https://www.irccloud.com/pastebin/JGXlYhj8","modified":1653299204,"id":"JGXlYhj8","size":744,"lines":20,"own_paste":false,"theme":"","date":1653299204}