Skip to content

Instantly share code, notes, and snippets.

@coreymcmahon
Created February 7, 2013 11:14
Show Gist options
  • Save coreymcmahon/4730356 to your computer and use it in GitHub Desktop.
Save coreymcmahon/4730356 to your computer and use it in GitHub Desktop.
A model implementation using the repository pattern and entity caching. From the article: PDO for Elegant PHP Database Access, http://www.modernphpbook.com/articles/pdo-for-elegant-php-database-access - Fig 5
<?php
class UserRepository
{
private $userCache = array();
public function find($id)
{
if (!isset($this->userCache[$id])) {
$userCache[$id] = $this->dao->query('
SELECT * FROM users WHERE id = ' . (int)$id . '
');
}
return $userCache[$id];
}
// etc...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment