Created
March 8, 2012 16:24
-
-
Save richthegeek/2001903 to your computer and use it in GitHub Desktop.
Variable microcaching with Laravel
This file contains 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 | |
Route::filter('cache', function($response = NULL) { | |
$cname = 'response-' . Str::slug(URI::full()); | |
if (!$response) { | |
return Cache::get($cname); | |
} | |
else if ($response->status == 200) { | |
$ctime = floor(pow(current(sys_getloadavg()) + 1, 5)); # cache for between 1 and 32 minutes | |
Cache::put($cname, $response, $ctime); | |
} | |
}); |
This file contains 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 | |
Route::get('foo', array('before' => 'cache', 'after' => 'cache', function() { | |
... | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Haha, I love my Windows :)
Thanks.