Created
February 11, 2016 07:03
-
-
Save hazeim254/658e07cef757c323346c to your computer and use it in GitHub Desktop.
Russian Caching inspired by Jeffry Way's class with an addition for local environmen
This file contains hidden or 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 | |
namespace App; | |
use Cache; | |
class RussianCaching | |
{ | |
/** | |
* A list of model cache keys. | |
* | |
* @param array $keys | |
*/ | |
protected static $keys = []; | |
/** | |
* Setup our caching mechanism. | |
* | |
* @param mixed $model | |
*/ | |
public static function setUp($model) | |
{ | |
if (app()->environment() === 'local') { | |
return ''; | |
} | |
static::$keys[] = $key = $model->getCacheKey(); | |
ob_start(); | |
return Cache::tags('views')->has($key); | |
} | |
/** | |
* Teardown our cache setup. | |
*/ | |
public static function tearDown() | |
{ | |
if (app()->environment() === 'local') { | |
return ''; | |
} | |
$key = array_pop(static::$keys); | |
$html = ob_get_clean(); | |
return Cache::tags('views') | |
->rememberForever($key, function () use ($html) { | |
return $html; | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
👍 Nice.
Same for teadDown method.