Skip to content

Instantly share code, notes, and snippets.

@caferrari
Last active December 19, 2015 08:39
Show Gist options
  • Save caferrari/5927580 to your computer and use it in GitHub Desktop.
Save caferrari/5927580 to your computer and use it in GitHub Desktop.
Cache Prototype
<?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