Skip to content

Instantly share code, notes, and snippets.

@mikemix
Last active August 13, 2022 18:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikemix/957f069044b06a36d11ea3c25f82f842 to your computer and use it in GitHub Desktop.
Save mikemix/957f069044b06a36d11ea3c25f82f842 to your computer and use it in GitHub Desktop.
<?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