the browser-facing portion of osu!
at master 25 lines 570 B view raw
1<?php 2 3// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the GNU Affero General Public License v3.0. 4// See the LICENCE file in the repository root for full licence text. 5 6namespace App\Traits; 7 8trait Memoizes 9{ 10 private $memoized = []; 11 12 public function resetMemoized(): void 13 { 14 $this->memoized = []; 15 } 16 17 protected function memoize(string $key, callable $function) 18 { 19 if (!array_key_exists($key, $this->memoized)) { 20 $this->memoized[$key] = $function(); 21 } 22 23 return $this->memoized[$key]; 24 } 25}