title: How to cache JSON API data in PHP?
body: <p>I'm trying to understand how to cache data from an API (PokeAPI to be precise) to limit the amount of calls the application makes for the data.</p>
  
  <p>For example, one of my functions gets "All Pokemon" from the API:</p>
  
  <pre><code> function getAllPokemon() {
        $url = 'http://pokeapi.co/api/v2/pokemon/?limit=151';
        $response = Requests::get($url);
        $allPokemonData = json_decode($response-&gt;body, true);
        return $allPokemonData;
      }
  </code></pre>
  
  <p>I use the data in this function to build a menu of list items in my pokedex app. How can I cache the JSON results so that I don't have to call the api everytime the page reloads?</p>
  
  <p>From my research I know the basics of what needs to be done, a cache needs to be created in a directory and the app needs to check to see if a cached file exists before making a call to the api, if does exist do not call, if it doesnt make a call to the api and cache for a specified amount of time - I cannot translate this into working code though? Can anyone show me and example or point me to any learning materials? Thanks in advance.</p>