Skip to content

Instantly share code, notes, and snippets.

@cursosdesarrolloweb
Created January 9, 2021 16:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cursosdesarrolloweb/554cbaa46ec1a1fb8bcb82cd2d0143f6 to your computer and use it in GitHub Desktop.
Save cursosdesarrolloweb/554cbaa46ec1a1fb8bcb82cd2d0143f6 to your computer and use it in GitHub Desktop.
<?php
class Home {
public function __invoke(Cache $cache) {
// buscamos el archivo en caché, si existe lo servimos
$cachedFile = $cache->load("home");
if ($cachedFile) return $cachedFile;
// En otro caso, hacemos 100 operaciones para obtener los datos necesarios
$view = view("home", compact("news", "tags", "authors", "ads"));
// ¡la próxima vez ya estará en caché!
$cache->save($view);
return $view;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment