Skip to content

Instantly share code, notes, and snippets.

@tystr
Last active January 5, 2016 00:02
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 tystr/f5488a1d1ed8bab0b3bb to your computer and use it in GitHub Desktop.
Save tystr/f5488a1d1ed8bab0b3bb to your computer and use it in GitHub Desktop.
Cache query result per request
<?php
// ...
private $repository;
private $cachedResults = [];
public function findAll()
{
if (!$this->isCached['findAll']) {
$this->cachedResults['findAll'] = $this->repository->findAll();
}
return $this->cachedResults['findAll'];
}
private function isCached($method)
{
return isset($this->cachedResults[$method]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment