if ( exists $self->foo_cache()->{$key} ) { # cache hit $value = $self->foo_cache()->{$key}; } else { # this means a cache miss $value = calculate_something_worth_caching(); $self->foo_cache()->{$key} = $value; # store in cache }