5 * Definition of Drush\Cache\JSONCache.
11 * JSON cache storage backend.
15 class JSONCache extends FileCache
17 const EXTENSION = '.json';
19 public function readFile($filename)
21 $item = file_get_contents($filename);
22 return $item ? (object)json_decode($item, true) : false;
25 public function writeFile($filename, $cache)
27 $json = json_encode($cache, JSON_PRETTY_PRINT);
28 // json_encode() does not escape <, > and &, so we do it with str_replace().
29 $json = str_replace(['<', '>', '&'], ['\u003c', '\u003e', '\u0026'], $json);
30 return file_put_contents($filename, $json);