Last active
August 15, 2016 16:18
-
-
Save chadtomkiss/52ef04cd2e606f32a1357e9d27050430 to your computer and use it in GitHub Desktop.
Caching API Shit
This file contains 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 | |
use Illuminate\Contracts\Cache\Repository as CacheRepository; | |
class ApiCache | |
{ | |
public function __construct(CacheRepository $cache, Api $api) | |
{ | |
$this->cache = $cache; | |
$this->api = $api; | |
} | |
public function users() | |
{ | |
$this->cache->remember('users', 90, function() { | |
return $this->api->users(); | |
}); | |
} | |
} | |
class Api | |
{ | |
public function users() | |
{ | |
// Guzzle HTTP request | |
// blah blah | |
return $users; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment