Last active
August 13, 2022 18:23
-
-
Save mikemix/957f069044b06a36d11ea3c25f82f842 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** @var LRUCacheInterface<User> $cache */ | |
$cache = new LRUCache(50); | |
foreach ($taskRepository->findAll() as $task) { | |
// get the user from cache | |
// phpStorm will correctly resolve the $user as the User class | |
$user = $cache->get($task->getUserId()); | |
if (null === $user) { | |
$user = $userRepository->findById($task->getUserId()); | |
$cache->add($user->getId(), $user); | |
} | |
$task->execute($user); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment