Skip to content

Latest commit

 

History

History
14 lines (12 loc) · 331 Bytes

inline_static_caching.md

File metadata and controls

14 lines (12 loc) · 331 Bytes

Inline static caching (memoization)

Little inline caches for when a method is called multiple times within a request and don't want to "re-compute" that value.

class Post extends Model
{
    public function commentCount()
    {
        static $cache;

        return $cache ?: $cache = $this->comment->count;
    }
}