Guest User

Untitled

a guest
Feb 16th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App\Observers;
  4.  
  5. use App\Product;
  6. use Illuminate\Support\Facades\Cache;
  7. use Illuminate\Support\Facades\DB;
  8.  
  9. class CacheProduct
  10. {
  11. public function created()
  12. {
  13. Cache::forget('products');
  14. Cache::remember('products', 60, function() {
  15. return DB::table('products')->get();
  16. });
  17. \Log::info('Cache atualizado');
  18. }
  19.  
  20. public function deleting(Product $product)
  21. {
  22. Cache::forget('products');
  23. Cache::remember('products', 60, function() {
  24. return DB::table('products')->get();
  25. });
  26. \Log::info('Cache atualizado');
  27. }
  28. }
Add Comment
Please, Sign In to add comment