# Pastebin JGXlYhj8 sub character-lookup(Int :$id) { # check the cache first my Bool $cached = True; my $character = $redis.get($id); # check the database if we didn't find it in the cache if !$character { $cached = False; $character = Character.^load($id).to-json; # cache the result we got from the database for 30 minutes if $character { $redis.setex($id, 1800, $character); } } given $cached { my $color; my $state; when ?* { $color = 'red'; $state = '[HIT]' } when !* { $color = 'blue'; $state = '[MISS]' } note "[{ DateTime.now }]" ~ color($color)," $state " ~ color('reset'), "Performing lookup on $id"; } # return the lookup result return $character; }