Last active
December 19, 2015 08:39
-
-
Save caferrari/5927580 to your computer and use it in GitHub Desktop.
Cache Prototype
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 | |
class Controller | |
{ | |
public function indexAction() | |
{ | |
$repo = $this->getRepository('User'); | |
$id = 10; | |
$cacheService = $this->getService('cache'); | |
// Get with Closure | |
$data = $cacheService("userDetails{$id}", function () use ($repo, $id) { | |
return $repo->findOneById($id); | |
}); | |
// Get with callable | |
$data = $cacheService("userDetails{$id}", array(array($repo, 'findOneById'), array($id))); | |
// Delete all | |
$cacheService->clear(); | |
// Delete Key | |
$cacheService->delele("userDetails{$id}"); | |
// Delete Prefix | |
$cacheService->delete('userDetails*'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment